Skip to content

Commit 2d21bff

Browse files
committed
chore: expect() --> unwrap_or_else()
1 parent 47171ce commit 2d21bff

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

stackslib/src/chainstate/stacks/db/accounts.rs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,26 @@ impl StacksChainState {
267267
})
268268
})
269269
.map_err(Error::ClarityError)
270-
.unwrap()
270+
.unwrap_or_else(|e| {
271+
error!(
272+
"FATAL: Failed to query account for {:?}: {:?}",
273+
principal, &e
274+
);
275+
panic!();
276+
})
271277
}
272278

273279
pub fn get_nonce<T: ClarityConnection>(clarity_tx: &mut T, principal: &PrincipalData) -> u64 {
274280
clarity_tx
275281
.with_clarity_db_readonly(|ref mut db| db.get_account_nonce(principal))
276282
.map_err(|x| Error::ClarityError(x.into()))
277-
.unwrap()
283+
.unwrap_or_else(|e| {
284+
error!(
285+
"FATAL: Failed to query account nonce for {:?}: {:?}",
286+
principal, &e
287+
);
288+
panic!();
289+
})
278290
}
279291

280292
pub fn get_account_ft(
@@ -337,7 +349,13 @@ impl StacksChainState {
337349
snapshot.save()?;
338350
Ok(())
339351
})
340-
.expect("FATAL: failed to debit account")
352+
.unwrap_or_else(|e| {
353+
error!(
354+
"FATAL: failed to debit account {:?} for {} uSTX: {:?}",
355+
principal, amount, &e
356+
);
357+
panic!();
358+
})
341359
}
342360

343361
/// Called each time a transaction sends STX to this principal.
@@ -358,7 +376,13 @@ impl StacksChainState {
358376
info!("{} credited: {} uSTX", principal, new_balance);
359377
Ok(())
360378
})
361-
.expect("FATAL: failed to credit account")
379+
.unwrap_or_else(|e| {
380+
error!(
381+
"FATAL: failed to credit account {:?} for {} uSTX: {:?}",
382+
principal, amount, &e
383+
);
384+
panic!();
385+
})
362386
}
363387

364388
/// Called during the genesis / boot sequence.
@@ -374,7 +398,13 @@ impl StacksChainState {
374398
snapshot.save()?;
375399
Ok(())
376400
})
377-
.expect("FATAL: failed to credit account")
401+
.unwrap_or_else(|e| {
402+
error!(
403+
"FATAL: failed to credit genesis account {:?} for {} uSTX: {:?}",
404+
principal, amount, &e
405+
);
406+
panic!();
407+
})
378408
}
379409

380410
/// Increment an account's nonce
@@ -385,11 +415,19 @@ impl StacksChainState {
385415
) {
386416
clarity_tx
387417
.with_clarity_db(|ref mut db| {
388-
let next_nonce = cur_nonce.checked_add(1).expect("OUT OF NONCES");
418+
let next_nonce = cur_nonce
419+
.checked_add(1)
420+
.unwrap_or_else(|| panic!("OUT OF NONCES"));
389421
db.set_account_nonce(&principal, next_nonce)?;
390422
Ok(())
391423
})
392-
.expect("FATAL: failed to set account nonce")
424+
.unwrap_or_else(|e| {
425+
error!(
426+
"FATAL: failed to update account nonce for account {:?} from {}: {:?}",
427+
principal, cur_nonce, &e
428+
);
429+
panic!();
430+
})
393431
}
394432

395433
/// Schedule a miner payment in the future.

0 commit comments

Comments
 (0)