-
Notifications
You must be signed in to change notification settings - Fork 375
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
feat(stdlibs/errors): support Is
function
#1929
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1929 +/- ##
==========================================
- Coverage 47.74% 45.96% -1.79%
==========================================
Files 393 483 +90
Lines 61629 69533 +7904
==========================================
+ Hits 29424 31959 +2535
- Misses 29734 34927 +5193
- Partials 2471 2647 +176 ☔ View full report in Codecov by Sentry. |
Is
function in the errors
package
Is
function in the errors
packageIs
function
for { | ||
if err == target { | ||
return true | ||
} | ||
|
||
if x, ok := err.(interface{ Is(error) bool }); ok && x.Is(target) { | ||
return true | ||
} | ||
|
||
if x, ok := err.(*errorString); ok { | ||
if t, ok := target.(*errorString); ok && x.s == t.s { | ||
return true | ||
} | ||
} | ||
|
||
if err = Unwrap(err); err == nil { | ||
return false | ||
} | ||
} |
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'm worried about edge cases here. Can it go infinite?
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 an infinity loop will be caused when trying to unwrap the circular referenced errors. this can be prevented by just tracing whether the error has been visited or not.
return e.msg == t.msg | ||
} | ||
|
||
func TestIs(t *testing.T) { |
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.
can we have same set of tests as errors/wrap.go:L16-69
?
should be approved by someone with better understanding
Co-authored-by: Hariom Verma <hariom18599@gmail.com>
For this code to fully work, the interface type of https://go.dev/play/p/XUDNrojJ2jh gno/gnovm/pkg/gnolang/gonative.go Lines 862 to 870 in b2f12a9
|
This PR is stale because it has been open 3 months with no activity. Remove stale label or comment or this will be closed in 3 months. |
Description
Added the
Is
function to theerrors
package.errorString
typeUnwrap
method to traverse the error chain to find an error that matches the target error.Relative Issue
#486 // Failed to implement
As
function due to the technical issue. maybe later