Compare commits

...

2 Commits

Author SHA1 Message Date
str4d 5d9a58930c
Merge pull request #132 from nuttycom/avoid_missing_account_panic
Return an error instead of a panic in the case of data corruption.
2024-04-17 18:42:19 +01:00
Kris Nuttycombe df52aa844d Return an error instead of a panic in the case of data corruption.
This removes an `expect` call that risked crashing the app in the case of
database corruption, potentially hiding other bugs.
2024-04-01 11:33:48 -06:00
1 changed files with 21 additions and 9 deletions

View File

@ -144,15 +144,27 @@ fn account_id_from_ffi<P: Parameters>(
.filter_map(|account_id| {
db_data
.get_account(account_id)
.transpose()
.expect("account_id exists")
.map(|account| match account.source() {
AccountSource::Derived { account_index, .. }
if account_index == requested_account_index =>
{
Some(account)
}
_ => None,
.map_err(|e| {
anyhow!(
"Database error encountered retrieving account {:?}: {}",
account_id,
e
)
})
.and_then(|acct_opt| {
acct_opt
.ok_or(anyhow!(
"Wallet data corrupted: unable to retrieve account data for account {:?}",
account_id
))
.map(|account| match account.source() {
AccountSource::Derived { account_index, .. }
if account_index == requested_account_index =>
{
Some(account)
}
_ => None,
})
})
.transpose()
});