chore(cli): replace unwrap() with expect() in non-test code - #8420
Merged
dpc merged 1 commit intoApr 7, 2026
Merged
Conversation
dpc
previously approved these changes
Mar 25, 2026
Contributor
|
Follow-up: forbid |
Replace bare unwrap() calls with descriptive expect() messages in fedimint-cli, following the project convention documented in CLAUDE.md: "Never use unwrap() in non-test code — Always use expect() with a succinct message explaining why the condition cannot fail." Also refactor checked_sub + is_none + unwrap pattern to idiomatic let-else in the withdraw command.
gabrielrondon
force-pushed
the
chore/replace-unwrap-with-expect-cli
branch
from
March 30, 2026 18:32
2dd8170 to
d6394a7
Compare
gabrielrondon
added a commit
to gabrielrondon/fedimint
that referenced
this pull request
Mar 30, 2026
Add `clippy::unwrap_used` to the deny list in `fedimint-cli` to prevent reintroduction of `unwrap()` calls in non-test code. Follow-up to fedimint#8420 which replaced all existing `unwrap()` with `expect()` in non-test code. This lint ensures the cleanup is maintained going forward. Allow the lint in the existing test function where `unwrap()` is acceptable.
dpc
approved these changes
Apr 7, 2026
gabrielrondon
added a commit
to gabrielrondon/fedimint
that referenced
this pull request
Apr 8, 2026
Add `clippy::unwrap_used` to the deny list in `fedimint-cli` to prevent reintroduction of `unwrap()` calls in non-test code. Follow-up to fedimint#8420 which replaced all existing `unwrap()` with `expect()` in non-test code. This lint ensures the cleanup is maintained going forward. Allow the lint in the existing test function where `unwrap()` is acceptable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace bare
unwrap()calls with descriptiveexpect()messages infedimint-cli, following the project convention documented inCLAUDE.md:Changes
fedimint-cli/src/client.rs(8 replacements):subscribe_reissue_external_notes().await.unwrap()→.expect("just created operation can't already be deleted")serde_json::to_value(amount).unwrap()→.expect("Amount is serializable")serde_json::to_value(LnInvoiceResponse{..}).unwrap()→.expect("LnInvoiceResponse is serializable")serde_json::to_value(Vec::<String>::new()).unwrap()→.expect("empty vec is serializable")serde_json::to_value(()).unwrap()→.expect("unit type is serializable")serde_json::to_value(InfoResponse{..}).unwrap()→.expect("InfoResponse is serializable")balance.checked_sub(fees).unwrap()→ refactored to idiomaticlet-elsepatternfedimint-cli/src/lib.rs(3 replacements):serde_json::to_string_pretty(self).unwrap()→.expect("CliOutput is serializable")serde_json::to_value(()).unwrap()→.expect("unit type is serializable")read_to_end(&mut plaintext_bytes).unwrap()→.expect("Could not read input cfg file")Test plan
expect()messages follow existing codebase patternslet-elserefactor inWithdrawpreserves identical behavior