Add toast when import errors

This commit is contained in:
trevor-signal 2024-11-15 17:01:11 -05:00 committed by GitHub
parent cce9670abd
commit e819bfe4eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 1 deletions

View file

@ -800,6 +800,10 @@
"messageformat": "Failed to send message with endorsements", "messageformat": "Failed to send message with endorsements",
"description": "An error popup when we attempted and failed to send a message using endorsements, only for internal users." "description": "An error popup when we attempted and failed to send a message using endorsements, only for internal users."
}, },
"icu:Toast--FailedToImportBackup": {
"messageformat": "Failed to process some frames during backup import. Please share your logs.",
"description": "[Only shown to internal users] An error popup when we failed to process some parts of a backup import."
},
"icu:cannotSelectPhotosAndVideosAlongWithFiles": { "icu:cannotSelectPhotosAndVideosAlongWithFiles": {
"messageformat": "You can't select photos and videos along with files.", "messageformat": "You can't select photos and videos along with files.",
"description": "An error popup when the user has attempted to add an attachment" "description": "An error popup when the user has attempted to add an attachment"

View file

@ -17,7 +17,7 @@
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
text-align: center; text-align: center;
margin-top: 72px; margin-top: 84px;
flex: 1; flex: 1;
} }

View file

@ -105,6 +105,8 @@ function getToast(toastType: ToastType): AnyToast {
return { toastType: ToastType.FailedToFetchUsername }; return { toastType: ToastType.FailedToFetchUsername };
case ToastType.FailedToSendWithEndorsements: case ToastType.FailedToSendWithEndorsements:
return { toastType: ToastType.FailedToSendWithEndorsements }; return { toastType: ToastType.FailedToSendWithEndorsements };
case ToastType.FailedToImportBackup:
return { toastType: ToastType.FailedToImportBackup };
case ToastType.FileSaved: case ToastType.FileSaved:
return { return {
toastType: ToastType.FileSaved, toastType: ToastType.FileSaved,

View file

@ -309,6 +309,20 @@ export function renderToast({
); );
} }
if (toastType === ToastType.FailedToImportBackup) {
return (
<Toast
onClose={hideToast}
toastAction={{
label: i18n('icu:Toast__ActionLabel--SubmitLog'),
onClick: onShowDebugLog,
}}
>
{i18n('icu:Toast--FailedToImportBackup')}
</Toast>
);
}
if (toastType === ToastType.FileSaved) { if (toastType === ToastType.FileSaved) {
return ( return (
<Toast <Toast

View file

@ -116,6 +116,8 @@ import {
} from '../../util/backupMediaDownload'; } from '../../util/backupMediaDownload';
import { getEnvironment, isTestEnvironment } from '../../environment'; import { getEnvironment, isTestEnvironment } from '../../environment';
import { hasAttachmentDownloads } from '../../util/hasAttachmentDownloads'; import { hasAttachmentDownloads } from '../../util/hasAttachmentDownloads';
import { isAlpha } from '../../util/version';
import { ToastType } from '../../types/Toast';
const MAX_CONCURRENCY = 10; const MAX_CONCURRENCY = 10;
@ -218,6 +220,7 @@ export class BackupImportStream extends Writable {
private releaseNotesRecipientId: Long | undefined; private releaseNotesRecipientId: Long | undefined;
private releaseNotesChatId: Long | undefined; private releaseNotesChatId: Long | undefined;
private pendingGroupAvatars = new Map<string, string>(); private pendingGroupAvatars = new Map<string, string>();
private frameErrorCount: number = 0;
private constructor(private readonly backupType: BackupType) { private constructor(private readonly backupType: BackupType) {
super({ objectMode: true }); super({ objectMode: true });
@ -359,6 +362,20 @@ export class BackupImportStream extends Writable {
await startBackupMediaDownload(); await startBackupMediaDownload();
} }
if (this.frameErrorCount > 0) {
log.error(
`${this.logId}: errored while processing ${this.frameErrorCount} frames.`
);
if (isAlpha(window.getVersion())) {
window.reduxActions.toast.showToast({
toastType: ToastType.FailedToImportBackup,
});
}
// TODO (DESKTOP-7934): throw in tests if we cannot process a frame
} else {
log.info(`${this.logId}: successfully processed all frames.`);
}
done(); done();
} catch (error) { } catch (error) {
done(error); done(error);
@ -440,6 +457,7 @@ export class BackupImportStream extends Writable {
log.warn(`${this.logId}: unsupported frame item ${frame.item}`); log.warn(`${this.logId}: unsupported frame item ${frame.item}`);
} }
} catch (error) { } catch (error) {
this.frameErrorCount += 1;
log.error( log.error(
`${this.logId}: failed to process a frame ${frame.item}, ` + `${this.logId}: failed to process a frame ${frame.item}, ` +
`${Errors.toLogFormat(error)}` `${Errors.toLogFormat(error)}`

View file

@ -50,6 +50,8 @@ import { BackupAPI } from './api';
import { validateBackup } from './validator'; import { validateBackup } from './validator';
import { BackupType } from './types'; import { BackupType } from './types';
import { UnsupportedBackupVersion } from './errors'; import { UnsupportedBackupVersion } from './errors';
import { ToastType } from '../../types/Toast';
import { isAlpha } from '../../util/version';
export { BackupType }; export { BackupType };
@ -385,6 +387,13 @@ export class BackupsService {
log.info('importBackup: finished...'); log.info('importBackup: finished...');
} catch (error) { } catch (error) {
log.info(`importBackup: failed, error: ${Errors.toLogFormat(error)}`); log.info(`importBackup: failed, error: ${Errors.toLogFormat(error)}`);
if (isAlpha(window.getVersion())) {
window.reduxActions.toast.showToast({
toastType: ToastType.FailedToImportBackup,
});
}
throw error; throw error;
} finally { } finally {
this.isRunning = false; this.isRunning = false;

View file

@ -35,6 +35,7 @@ export enum ToastType {
FailedToFetchPhoneNumber = 'FailedToFetchPhoneNumber', FailedToFetchPhoneNumber = 'FailedToFetchPhoneNumber',
FailedToFetchUsername = 'FailedToFetchUsername', FailedToFetchUsername = 'FailedToFetchUsername',
FailedToSendWithEndorsements = 'FailedToSendWithEndorsements', FailedToSendWithEndorsements = 'FailedToSendWithEndorsements',
FailedToImportBackup = 'FailedToImportBackup',
FileSaved = 'FileSaved', FileSaved = 'FileSaved',
FileSize = 'FileSize', FileSize = 'FileSize',
GroupLinkCopied = 'GroupLinkCopied', GroupLinkCopied = 'GroupLinkCopied',
@ -113,6 +114,7 @@ export type AnyToast =
| { toastType: ToastType.FailedToFetchPhoneNumber } | { toastType: ToastType.FailedToFetchPhoneNumber }
| { toastType: ToastType.FailedToFetchUsername } | { toastType: ToastType.FailedToFetchUsername }
| { toastType: ToastType.FailedToSendWithEndorsements } | { toastType: ToastType.FailedToSendWithEndorsements }
| { toastType: ToastType.FailedToImportBackup }
| { | {
toastType: ToastType.FileSaved; toastType: ToastType.FileSaved;
parameters: { fullPath: string; countOfFiles?: number }; parameters: { fullPath: string; countOfFiles?: number };