mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Better handle backup errors (#2132)
This commit is contained in:
parent
c223510438
commit
b1e5d1503e
2 changed files with 13 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
await backupService.importBackupFile(file, password);
|
||||
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>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue