@@ -379,25 +379,31 @@ std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& b
379
379
ReadDatabaseArgs (*context.args , options);
380
380
options.require_existing = true ;
381
381
382
- if (!fs::exists (backup_file)) {
383
- error = Untranslated (" Backup file does not exist" );
384
- status = DatabaseStatus::FAILED_INVALID_BACKUP_FILE;
385
- return nullptr ;
386
- }
387
-
388
382
const fs::path wallet_path = fsbridge::AbsPathJoin (GetWalletDir (), fs::u8path (wallet_name));
383
+ auto wallet_file = wallet_path / " wallet.dat" ;
384
+ std::shared_ptr<CWallet> wallet;
389
385
390
- if (fs::exists (wallet_path) || !TryCreateDirectories (wallet_path)) {
391
- error = Untranslated (strprintf (" Failed to create database path '%s'. Database already exists." , fs::PathToString (wallet_path)));
392
- status = DatabaseStatus::FAILED_ALREADY_EXISTS;
393
- return nullptr ;
394
- }
386
+ try {
387
+ if (!fs::exists (backup_file)) {
388
+ error = Untranslated (" Backup file does not exist" );
389
+ status = DatabaseStatus::FAILED_INVALID_BACKUP_FILE;
390
+ return nullptr ;
391
+ }
395
392
396
- auto wallet_file = wallet_path / " wallet.dat" ;
397
- fs::copy_file (backup_file, wallet_file, fs::copy_options::none);
393
+ if (fs::exists (wallet_path) || !TryCreateDirectories (wallet_path)) {
394
+ error = Untranslated (strprintf (" Failed to create database path '%s'. Database already exists." , fs::PathToString (wallet_path)));
395
+ status = DatabaseStatus::FAILED_ALREADY_EXISTS;
396
+ return nullptr ;
397
+ }
398
398
399
- auto wallet = LoadWallet (context, wallet_name, load_on_start, options, status, error, warnings );
399
+ fs::copy_file (backup_file, wallet_file, fs::copy_options::none );
400
400
401
+ wallet = LoadWallet (context, wallet_name, load_on_start, options, status, error, warnings);
402
+ } catch (const std::exception& e) {
403
+ assert (!wallet);
404
+ if (!error.empty ()) error += Untranslated (" \n " );
405
+ error += strprintf (Untranslated (" Unexpected exception: %s" ), e.what ());
406
+ }
401
407
if (!wallet) {
402
408
fs::remove (wallet_file);
403
409
fs::remove (wallet_path);
0 commit comments