Skip to content

Commit faf3698

Browse files
committed
wallet: Improve log output for errors during load
When loading the wallet, display the entire path in error messages, instead of the name (which, for the default wallet, is the empty string.) When an exception occurs during wallet loading, display e.what() if possible, instead of nothing.
1 parent 4952a95 commit faf3698

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/wallet/db.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ bool IsWalletLoaded(const fs::path& wallet_path)
8484
return database && database->IsDatabaseLoaded(database_filename);
8585
}
8686

87+
fs::path WalletDataFilePath(const fs::path& wallet_path)
88+
{
89+
fs::path env_directory;
90+
std::string database_filename;
91+
SplitWalletPath(wallet_path, env_directory, database_filename);
92+
return env_directory / database_filename;
93+
}
94+
8795
/**
8896
* @param[in] wallet_path Path to wallet directory. Or (for backwards compatibility only) a path to a berkeley btree data file inside a wallet directory.
8997
* @param[out] database_filename Filename of berkeley btree data file inside the wallet directory.

src/wallet/db.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class BerkeleyEnvironment
101101
/** Return whether a wallet database is currently loaded. */
102102
bool IsWalletLoaded(const fs::path& wallet_path);
103103

104+
/** Given a wallet directory path or legacy file path, return path to main data file in the wallet database. */
105+
fs::path WalletDataFilePath(const fs::path& wallet_path);
106+
104107
/** Get BerkeleyEnvironment and database filename given a wallet path. */
105108
std::shared_ptr<BerkeleyEnvironment> GetWalletEnv(const fs::path& wallet_path, std::string& database_filename);
106109

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4074,7 +4074,7 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b
40744074

40754075
std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, uint64_t wallet_creation_flags)
40764076
{
4077-
const std::string& walletFile = location.GetName();
4077+
const std::string& walletFile = WalletDataFilePath(location.GetPath()).string();
40784078

40794079
// needed to restore wallet transaction meta data after -zapwallettxes
40804080
std::vector<CWalletTx> vWtx;

src/wallet/walletdb.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,15 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
422422
strType != "minversion" && strType != "acentry") {
423423
wss.m_unknown_records++;
424424
}
425-
} catch (...)
426-
{
425+
} catch (const std::exception& e) {
426+
if (strErr.empty()) {
427+
strErr = e.what();
428+
}
429+
return false;
430+
} catch (...) {
431+
if (strErr.empty()) {
432+
strErr = "Caught unknown exception in ReadKeyValue";
433+
}
427434
return false;
428435
}
429436
return true;

0 commit comments

Comments
 (0)