From 203641cebe1516dd0ed5017c5bf57729cbebfedd Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Fri, 20 Jan 2023 16:12:21 +0100 Subject: [PATCH] adding support for nil errors (#52) --- errors/errors.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/errors/errors.go b/errors/errors.go index 9ad16fc..e1f790f 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -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 @@ -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 } }