Skip to content

Commit f15a1b9

Browse files
committed
merge bitcoin#26005: Fix error handling (copy_file failure in RestoreWallet, and in general via interfaces)
includes: - c3e5365 continuation of b75f1ad from dash#6733
1 parent 240765e commit f15a1b9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/wallet/interfaces.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,12 @@ class WalletLoaderImpl : public WalletLoader
617617
options.create_flags = wallet_creation_flags;
618618
options.create_passphrase = passphrase;
619619
bilingual_str error;
620-
util::Result<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, CreateWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
621-
return wallet ? std::move(wallet) : util::Error{error};
620+
std::unique_ptr<Wallet> wallet{MakeWallet(m_context, CreateWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
621+
if (wallet) {
622+
return {std::move(wallet)};
623+
} else {
624+
return util::Error{error};
625+
}
622626
}
623627
util::Result<std::unique_ptr<Wallet>> loadWallet(const std::string& name, std::vector<bilingual_str>& warnings) override
624628
{
@@ -627,15 +631,23 @@ class WalletLoaderImpl : public WalletLoader
627631
ReadDatabaseArgs(*m_context.args, options);
628632
options.require_existing = true;
629633
bilingual_str error;
630-
util::Result<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, LoadWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
631-
return wallet ? std::move(wallet) : util::Error{error};
634+
std::unique_ptr<Wallet> wallet{MakeWallet(m_context, LoadWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
635+
if (wallet) {
636+
return {std::move(wallet)};
637+
} else {
638+
return util::Error{error};
639+
}
632640
}
633641
util::Result<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) override
634642
{
635643
DatabaseStatus status;
636644
bilingual_str error;
637-
util::Result<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))};
638-
return wallet ? std::move(wallet) : util::Error{error};
645+
std::unique_ptr<Wallet> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))};
646+
if (wallet) {
647+
return {std::move(wallet)};
648+
} else {
649+
return util::Error{error};
650+
}
639651
}
640652
std::string getWalletDir() override
641653
{

0 commit comments

Comments
 (0)