fix: replace unwrap() with ? in AccountWitness::new() TryFrom impl#1957
fix: replace unwrap() with ? in AccountWitness::new() TryFrom impl#1957igamigo merged 2 commits into0xMiden:nextfrom
Conversation
|
can you retry the merge? |
|
Hello @bigeez, thanks for the PR. Can you rebase this to the latest |
b3e9fd9 to
e3afdb3
Compare
|
Hi @igamigo, done! Thanks for the guidance! |
|
I think this might be missing some changes. The PR description mentions four different changes but the diff shows one. |
|
the 3 other fixes were dropped during the rebase cleanup, I've added them back as seperate commits |
igamigo
left a comment
There was a problem hiding this comment.
Let's just keep the AccountWitness change. The other ones express invariants that shouldn't be broken and not errors that make sense for the user to react to in any way
| @@ -580,7 +580,11 @@ impl SqliteStore { | |||
| } | |||
|
|
|||
| // Step 4: Restore old header from the earliest discarded nonce | |||
There was a problem hiding this comment.
Let's add a safety comment to this expressing while the unwrap() was safe
`undo_account_nonces` is only called for accounts present in `nonces_by_account`, which only gets entries when at least one nonce is pushed — so `nonces` is guaranteed non-empty at the unwrap site. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bf7ca51 to
e99063c
Compare
|
I've dropped the chain_data and request/mod changes, and replaced the accounts.rs unwrap change with a safety comment explaining the invariant instead. The PR now has just two commits:
|
Summary
Replaces 4
unwrap()/expect()calls in production code with proper error propagation using?andmap_err().Changes
1.
crates/rust-client/src/rpc/domain/account.rsAccountWitness::new().unwrap()inside aTryFromimpl where everything else uses?. Applied the same.map_err(|err| RpcError::InvalidResponse(format!("{err}")))?pattern already used in the same file.2.
crates/sqlite-store/src/chain_data.rsNonZeroUsize::new().unwrap()andusize::try_from().expect()when parsing DB data. A zero or overflow value would panic inside aResult-returning function. Both now returnStoreError::ParsingError.3.
crates/sqlite-store/src/account/accounts.rsnonces.last().unwrap()with no empty-slice guard inundo_account_nonces(). Now returnsStoreError::ParsingErrorifnoncesis empty.4.
crates/rust-client/src/transaction/request/mod.rs.expect()ontry_into()insidebuild_input_notes()which returnsResult. AddedNoteRecordErrorvariant toTransactionRequestErrorand propagated with?.Result
Result-returning functions replaced with proper error propagation