Better handle backup errors (#2132)

This commit is contained in:
Omar Hatem 2025-03-28 16:17:38 +02:00 committed by GitHub
parent c223510438
commit b1e5d1503e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View file

@ -198,7 +198,7 @@ class BackupServiceV3 extends $BackupService {
final version = getVersionFile(file);
switch (version) {
case BackupVersion.unknown:
throw Exception('Invalid backup file: unknown version');
throw Exception('unknown_backup_version');
case BackupVersion.v1:
final data = file.readAsBytesSync();
final backupBytes = data.toList()..removeAt(0);

View file

@ -7,7 +7,6 @@ import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/main.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/core/backup_service.dart';
import 'package:cw_core/node.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/authentication_store.dart';
@ -44,13 +43,22 @@ abstract class RestoreFromBackupViewModelBase with Store {
final file = File(filePath);
try {
await backupService.importBackupFile(file, password);
} catch (e, s) {
if (e.toString().contains("unknown_backup_version")) {
state = FailureState('This is not a valid backup file, please make sure you selected the correct backup file');
} else {
state = FailureState('Failed to restore backup, please try again');
ExceptionHandler.onError(FlutterErrorDetails(exception: e, stack: s, silent: true));
}
}
try {
await initializeAppAtRoot(reInitializing: true);
} catch (e, s) {
throw Exception('failed_app_initialization: $e $s');
state = FailureState('Failed app initialization, please try again');
ExceptionHandler.onError(FlutterErrorDetails(exception: e, stack: s, silent: true));
}
final store = getIt.get<AppStore>();