-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Wallet: Fix error handling (copy_file failure in RestoreWallet, and in general via interfaces) #26005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wallet: Fix error handling (copy_file failure in RestoreWallet, and in general via interfaces) #26005
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK c1cd7b4.
Not sure if b60a2ce ("Bugfix: Wallet: Wrap RestoreWallet content in a try block ...") is needed.
See #22541 (comment).
Without it, the GUI crashes quite uncleanly (bitcoin-core/gui#661), and an empty directory is left behind. |
} | ||
util::Result<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) override | ||
{ | ||
DatabaseStatus status; | ||
bilingual_str error; | ||
util::Result<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
This is a partial fix for a GUI crash bitcoin-core/gui#661 that avoids the crash but doesn't fix the restoreWallet error reporting. bitcoin#26005 is a more complete fix.
The Or maybe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK c1cd7b4
c1cd7b4
to
b298bee
Compare
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK b298bee
ACK b298bee |
…xceptions become returned errors and incomplete wallet directory is removed
b298bee
to
6c5af62
Compare
… CreateWallet/LoadWallet/RestoreWallet fail
6c5af62
to
c3e5365
Compare
ACK c3e5365 |
… RestoreWallet, and in general via interfaces) c3e5365 Bugfix: Wallet: Return util::Error rather than non-error nullptr when CreateWallet/LoadWallet/RestoreWallet fail (Luke Dashjr) 335ff98 Bugfix: Wallet: Wrap RestoreWallet content in a try block to ensure exceptions become returned errors and incomplete wallet directory is removed (Luke Dashjr) Pull request description: Bug 1: `copy_file` can throw exceptions, but `RestoreWallet` is expected to return a nullptr with a populated `errors` parameter. This is fixed by wrapping `copy_file` and `LoadWallet` (for good measure) in a `try` block, and converting any exceptions to the intended return style. Bug 2: `util::Result` turns what would have been a `false` unique_ptr into a `true` nullptr result, which leads to nullptr dereferences in at least the 3 cases of wallet creation/loading/restoring. This is fixed by keeping the pointer as a plain `std::unique_ptr` until actually returning it (ie, after the nullptr check). Fixes bitcoin-core/gui#661 ACKs for top commit: achow101: ACK c3e5365 Tree-SHA512: 4291b3dbbb147acea2e63a704324c9371bc16ecb4237f8753729b0b0a6e55c9758ad61bfe8bd432fd7b0bae95d8b63a9831e61ac8b8d5c0197b550a2e0f4a105
This is a partial fix for a GUI crash bitcoin-core/gui#661 that avoids the crash but doesn't fix the restoreWallet error reporting. bitcoin#26005 is a more complete fix.
Bug 1:
copy_file
can throw exceptions, butRestoreWallet
is expected to return a nullptr with a populatederrors
parameter. This is fixed by wrappingcopy_file
andLoadWallet
(for good measure) in atry
block, and converting any exceptions to the intended return style.Bug 2:
util::Result
turns what would have been afalse
unique_ptr into atrue
nullptr result, which leads to nullptr dereferences in at least the 3 cases of wallet creation/loading/restoring. This is fixed by keeping the pointer as a plainstd::unique_ptr
until actually returning it (ie, after the nullptr check).Fixes bitcoin-core/gui#661