Skip to content

Commit 4b1d48a

Browse files
committed
Merge bitcoin/bitcoin#32598: walletdb: Log additional exception error messages for corrupted wallets
ad9a13f walletdb: Log additional exception error messages for corrupted wallets (Ava Chow) Pull request description: Many exceptions thrown for corruption are `std::runtime_error`; we should catch those and log the message to help with debugging. Split from #32489 ACKs for top commit: davidgumberg: ACK bitcoin/bitcoin@ad9a13f furszy: ACK ad9a13f rkrux: ACK ad9a13f Sjors: utACK ad9a13f Tree-SHA512: 107b938d67346804733ea27c44ed38822db0e020e5b1ac889ee35280d812ec56dcc9af7b3eab7a521d72cdd9cb4a8d6d35f3a3dfbcb2a6fd170a981f34fbdfc2
2 parents b933813 + ad9a13f commit 4b1d48a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/wallet/walletdb.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ bool HasLegacyRecords(CWallet& wallet, DatabaseBatch& batch)
541541
std::unique_ptr<DatabaseCursor> cursor = batch.GetNewPrefixCursor(prefix);
542542
if (!cursor) {
543543
// Could only happen on a closed db, which means there is an error in the code flow.
544-
wallet.WalletLogPrintf("Error getting database cursor for '%s' records", type);
545544
throw std::runtime_error(strprintf("Error getting database cursor for '%s' records", type));
546545
}
547546

@@ -1194,9 +1193,15 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
11941193

11951194
// Load decryption keys
11961195
result = std::max(LoadDecryptionKeys(pwallet, *m_batch), result);
1197-
} catch (...) {
1196+
} catch (std::runtime_error& e) {
11981197
// Exceptions that can be ignored or treated as non-critical are handled by the individual loading functions.
11991198
// Any uncaught exceptions will be caught here and treated as critical.
1199+
// Catch std::runtime_error specifically as many functions throw these and they at least have some message that
1200+
// we can log
1201+
pwallet->WalletLogPrintf("%s\n", e.what());
1202+
result = DBErrors::CORRUPT;
1203+
} catch (...) {
1204+
// All other exceptions are still problematic, but we can't log them
12001205
result = DBErrors::CORRUPT;
12011206
}
12021207

0 commit comments

Comments
 (0)