Wallet: Fix error handling (copy_file failure in RestoreWallet, and in general via interfaces)#26005
Conversation
There was a problem hiding this comment.
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. |
src/wallet/interfaces.cpp
Outdated
|
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 |
ryanofsky
left a comment
There was a problem hiding this comment.
Code review ACK c1cd7b4ac60d00dec369b3fe8f883cad07fbe833
c1cd7b4 to
b298bee
Compare
Done |
|
ACK b298beed38fba06d354e44778e6ecb3526feec1d |
…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_filecan throw exceptions, butRestoreWalletis expected to return a nullptr with a populatederrorsparameter. This is fixed by wrappingcopy_fileandLoadWallet(for good measure) in atryblock, and converting any exceptions to the intended return style.Bug 2:
util::Resultturns what would have been afalseunique_ptr into atruenullptr 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_ptruntil actually returning it (ie, after the nullptr check).Fixes bitcoin-core/gui#661