-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor: Error
type
#1270
Conversation
Co-authored-by: MujkicA <32431923+MujkicA@users.noreply.github.com>
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.
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 String
s.
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);
}
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.
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>
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.
IMO Codec
error should be used more often instead of Other
, other than that some nitpicks.
Co-authored-by: iqdecay <victor@berasconsulting.com>
Co-authored-by: iqdecay <victor@berasconsulting.com>
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!
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