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: Error type #1270

Merged
merged 22 commits into from
Feb 20, 2024
Merged

refactor: Error type #1270

merged 22 commits into from
Feb 20, 2024

Conversation

hal3e
Copy link
Contributor

@hal3e hal3e commented Feb 8, 2024

closes: #1236

All the suggestions from the issue were incorporated. In addition, error messages were changed to follow the guidelines from rust-api-guidelines i.e. The error message given by the Display representation of an error type should be lowercase without trailing punctuation, and typically concise.

BREAKING CHANGE: the fuels-rs Error type is changed together with the error messages.

Checklist

  • I have linked to any relevant issues.
  • I have updated the documentation.
  • I have added necessary labels.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@hal3e hal3e added tech-debt Improves code quality or safety breaking Introduces or requires breaking changes labels Feb 8, 2024
@hal3e hal3e self-assigned this Feb 8, 2024
Copy link
Contributor

@segfault-magnet segfault-magnet left a comment

Choose a reason for hiding this comment

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

Great work.

I'd like to raise just one issue while we're on the subject of errors. Sometimes I feel like we should add more context to our errors.

Due to the use of ? in the sdk we just bubble up what are essentially low-level errors.

Failure to decode a contract response will be reported something like:
"Expected 8 B got 0" (off the top of my head)

"Not enough coins to fit the target"
without explaining that we were trying, for example, to cover gas costs or cover the users asset requirements.

Context can be added either by having every "layer" have its own errors or by having something akin to anyhow's Context where we can add more context in the form of Strings.

Ultimately resulting in:

Failed to call `get_large_state(). Cause: Other, Not enough coins to fit the target
Context:
0. calling `get_large_state`
1. preparing transaction
2. adding coins to fit gas costs

Striking a balance between the verbosity of a backtrace and the terseness of 'Not enough coins to fit the target'.

Since most of the context entries would not be something users would like to match on, maybe an option similar to anyhow's Context would be best?

Would mean wrapping the sdk Error in a struct and exposing the cause with a getter:

let call_result = contract_instance.methods()...;
if let Error(err) = call_result {
  let cause: Cause = err.cause();
  // match on cause if needed
  // Otherwise just print and get the cause and some context
  eprintln!("{}", err);
} 

Copy link
Contributor

@iqdecay iqdecay left a comment

Choose a reason for hiding this comment

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

Overall looks great, I have some questions (that maybe can be boiled down to personal preferences).

Co-authored-by: iqdecay <victor@berasconsulting.com>
Co-authored-by: iqdecay <victor@berasconsulting.com>
Copy link
Contributor

@iqdecay iqdecay left a comment

Choose a reason for hiding this comment

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

IMO Codec error should be used more often instead of Other, other than that some nitpicks.

hal3e and others added 5 commits February 16, 2024 11:45
Copy link
Contributor

@iqdecay iqdecay left a comment

Choose a reason for hiding this comment

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

LGTM!

@hal3e hal3e merged commit 86e3cc7 into master Feb 20, 2024
41 checks passed
@hal3e hal3e deleted the hal3e/refactor-error branch February 20, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Introduces or requires breaking changes tech-debt Improves code quality or safety
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trim down variants of the Error type
5 participants