-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use thiserror
in the client
#623
Conversation
f6a4285
to
a1cdab0
Compare
ef97adb
to
b44f79b
Compare
7c8fe96
to
089ef2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Left a couple of minor comments. Also, two things:
- We could use this PR to fix errors related to this PR in
miden-base
, by temporarily pointing to that branch or waiting for it to be merged. - I think there are some places where we could use
#[from]
to simplify conversions, though probably not for this PR. The thing to keep in mind here would be to be careful about conversions depending on the context as well (see this discussion)
crates/rust-client/src/rpc/errors.rs
Outdated
NoteTypeError(NoteError), | ||
#[error("invalid note type value")] | ||
NoteTypeError(#[source] NoteError), | ||
#[error("field `{field_name}` required to be filled in protobuf representation of {entity}")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Let's change this to something like:
#[error("field `{field_name}` required to be filled in protobuf representation of {entity}")] | |
#[error("field `{field_name}` expected to be present in protobuf representation of {entity}")] |
ConversionError(String), | ||
/// Invalid underlying note object. | ||
NoteError(NoteError), | ||
#[error("note error: {0}")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As NoteError
is the source here, it should not be added to the Display
impl or otherwise it'll be duplicated on the reports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, though I left a couple minor comments.
crates/rust-client/src/errors.rs
Outdated
#[error("can't import new account without seed")] | ||
ImportNewAccountWithoutSeed, | ||
#[error("error with merkle path: {0}")] | ||
//TODO: use source in this error when possible | ||
MerkleError(MerkleError), | ||
#[error("the transaction did not produce the expected notes corresponding to note ids")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should decide if we are going to use contractions (do not -> don't, did not -> didn't) and commit to it. Maybe I'm being too picky. Feel free to left your opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's picky. This PR is a good opportunity to look into these details and update all of the error messages.
I think I prefer contractions, just to make the error messages shorter.
pub enum AccountProofError { | ||
#[error("the received account hash does not match the received account header's account hash")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[error("the received account hash does not match the received account header's account hash")] | |
#[error("the received account hash does not match the received account header's hash")] |
Refactor the client's errors to follow the new error design guidelines.
Some of the errors couldn't be marked with
#[source]
as they are not yet refactored in their crates. Specifically, once 0xPolygonMiden/miden-vm#1588 gets merged we can modify them.