-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Description
Proposal Details
Problem
The code looks redundant and cumbersome in cases when you need to check an error match several times. Example:
func foo() {
err := bar()
if errors.Is(err, err1) || errors.Is(err, err2) || errors.Is(err, err3) {
// some logic
}
}
Solution
A new function that will allow you to check for errors like this:
func foo() {
err := bar()
if errors.In(err, err1, err2, err3) {
// some logic
}
}
Implementation
package errors
func In(err error, target ...error) bool {
for _, v := range target {
if errors.Is(err, v) {
return true
}
}
return false
}
wizardishungry, koaim, depux, mauri870, Svetskiy and 4 moregazerro, earthboundkid, seankhliao and mxey
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Incoming