Skip to content
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

Merged
merged 2 commits into from
Dec 5, 2024
Merged

refactor: use thiserror in the client #623

merged 2 commits into from
Dec 5, 2024

Conversation

tomyrd
Copy link
Collaborator

@tomyrd tomyrd commented Dec 3, 2024

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.

@tomyrd tomyrd force-pushed the tomyrd-next-update branch from f6a4285 to a1cdab0 Compare December 3, 2024 17:26
Base automatically changed from tomyrd-next-update to next December 3, 2024 18:24
@tomyrd tomyrd marked this pull request as ready for review December 4, 2024 18:05
Copy link
Collaborator

@igamigo igamigo left a 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)

NoteTypeError(NoteError),
#[error("invalid note type value")]
NoteTypeError(#[source] NoteError),
#[error("field `{field_name}` required to be filled in protobuf representation of {entity}")]
Copy link
Collaborator

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:

Suggested change
#[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}")]
Copy link
Collaborator

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.

Copy link
Collaborator

@SantiagoPittella SantiagoPittella left a 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.

Comment on lines 42 to 47
#[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")]
Copy link
Collaborator

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.

Copy link
Collaborator Author

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")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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")]

@tomyrd tomyrd merged commit 6709fc8 into next Dec 5, 2024
15 checks passed
@tomyrd tomyrd deleted the tomyrd-thiserror branch December 5, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants