-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: errors: In() to check Is against multiple errors #70961
Comments
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
I don't think it's a very common thing to do: |
How about // Match returns the matched error in targets for err.
func Match(err error, targets ...error) error ? |
Besides the if condition with multiple var persistentErrors := []error{...}
func isPersistentError(err error) bool {
for _, e := range persistentErrors {
if errors.Is(err, e) {
return true
}
}
return false
} This would simply turn into a single line with this proposal. |
I don't think that would be correct. |
Proposal Details
Problem
The code looks redundant and cumbersome in cases when you need to check an error match several times. Example:
Solution
A new function that will allow you to check for errors like this:
Implementation
The text was updated successfully, but these errors were encountered: