feat: better backup errors (#2290)

Instead of creating error reports show the error to user use BackupVersion.unknown

cyan committed May 26, 2025 at 10:38 UTC e03dcc7fe94052c65674744fec97686656eb8d01
3 files changed +18 -8
lib/core/backup_service_v3.dart
+2 -2
@@ -177,7 +177,7 @@ class BackupServiceV3 extends $BackupService {
177 final archive = ZipDecoder().decodeStream(inputStream);
178 final metadataFile = archive.findFile('metadata.json');
179 if (metadataFile == null) {
180 - throw Exception('Invalid v3 backup: missing metadata.json');
180 + return BackupVersion.unknown;
181 }
182 final metadataBytes = metadataFile.rawContent!.readBytes();
183 final metadataString = utf8.decode(metadataBytes);
@@ -188,7 +188,7 @@ class BackupServiceV3 extends $BackupService {
188 }
189 }
190
191 - throw Exception('Invalid backup file: unknown version');
191 + return BackupVersion.unknown;
192 } finally {
193 raf.closeSync();
194 }
lib/src/screens/restore/restore_from_backup_page.dart
+13 -2
@@ -173,8 +173,19 @@ class RestoreFromBackupPage extends BasePage {
173
174 return;
175 }
176 -
177 - await restoreFromBackupViewModel.import(textEditingController.text);
176 + try {
177 + await restoreFromBackupViewModel.import(textEditingController.text);
178 + } catch (e) {
179 + await showPopUp<void>(
180 + context: context,
181 + builder: (_) {
182 + return AlertWithOneAction(
183 + alertTitle: S.current.error,
184 + alertContent: e.toString(),
185 + buttonText: S.of(context).ok,
186 + buttonAction: () => Navigator.of(context).pop());
187 + });
188 + }
189 textEditingController.text = '';
190 }
191 }
lib/view_model/restore_from_backup_view_model.dart
+3 -4
@@ -45,12 +45,11 @@ abstract class RestoreFromBackupViewModelBase with Store {
45
46 try {
47 await backupService.importBackupFile(file, password);
48 - } catch (e, s) {
48 + } catch (e) {
49 if (e.toString().contains("unknown_backup_version")) {
50 - state = FailureState('This is not a valid backup file, please make sure you selected the correct backup file');
50 + state = FailureState('This is not a valid backup file, please make sure you have selected the correct one');
51 } else {
52 - state = FailureState('Failed to restore backup, please try again');
53 - ExceptionHandler.onError(FlutterErrorDetails(exception: e, stack: s));
52 + state = FailureState(e.toString());
53 }
54 }
55