Skip to content

Commit

Permalink
adding support for nil errors (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 authored Jan 20, 2023
1 parent 2528ccb commit 203641c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package errorutil

import (
"fmt"
"strings"
)

// IsAny checks if err is not nil and matches any one of errxx errors
// if match successful returns true else false
// Note: no unwrapping is done here
Expand All @@ -15,14 +20,12 @@ func IsAny(err error, errxx ...error) bool {
}
} else {
for _, v := range errxx {
if v == nil {
continue
// check if v is an enriched error
if ee, ok := v.(Error); ok && ee.Equal(err) {
return true
}
if ee, ok := v.(Error); ok {
if ee.Equal(err) {
return true
}
} else if v.Error() == ee.Error() {
// check standard error equality
if strings.EqualFold(err.Error(), fmt.Sprint(v)) {
return true
}
}
Expand Down

0 comments on commit 203641c

Please sign in to comment.