-
Notifications
You must be signed in to change notification settings - Fork 650
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 UpgradeError to use bullt in errors functions #5704
Conversation
return errors.Is(u.err, err) | ||
// Is returns true if the of the provided error is an upgrade error. | ||
func (*UpgradeError) Is(err error) bool { | ||
_, ok := err.(*UpgradeError) |
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 think this is the simplest approach, by implementing it this way, when we call errors.Is
with an UpgradeError
as an argument, it will handle the traversal of the error stack and eventually hit this.
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.
yes! This is also what stdlib suggests https://pkg.go.dev/errors#Is
func (u *UpgradeError) Unwrap() error { | ||
return u.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.
when we call errors.Is
, it will call Unwrap
to traverse the stack.
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.
Looks much cleaner! Nice 👍🏻
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.
looks way better! thanks for looking into the clean up!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5704 +/- ##
==========================================
- Coverage 81.25% 81.24% -0.01%
==========================================
Files 199 199
Lines 15230 15224 -6
==========================================
- Hits 12375 12369 -6
Misses 2389 2389
Partials 466 466
|
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.
Excellent! Thank you @chatton looking into this! The changes look super clean to me :)
(cherry picked from commit 97ea045)
Description
This PR does a refactor to utilize the
errors.Is
anderrors.Unwrap
functions.@DimitrisJim pointed out we were using the
Unrwap
andCause
incorrectly. The implementations have been updated to reflect their intended use case.Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
).godoc
comments.Files changed
in the Github PR explorer.Codecov Report
in the comment section below once CI passes.