Skip to content

Commit

Permalink
fix: Is() should test the types of two errors is equals
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Feb 11, 2022
1 parent 187531d commit d8fa44b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,13 @@ func Is(err, target error) bool {

isComparable := reflect.TypeOf(target).Comparable()
for {
if isComparable && err == target {
return true
if isComparable {
if err == target {
return true
}
if reflect.TypeOf(target) == reflect.TypeOf(err) {
return true
}
}
if x, ok := err.(interface{ Is(error) bool }); ok && x.Is(target) {
return true
Expand Down Expand Up @@ -545,10 +550,14 @@ func IsSlice(errs []error, target error) bool {
isComparable := reflect.TypeOf(target).Comparable()
for {
if isComparable {
tt := reflect.TypeOf(target)
for _, e := range errs {
if e == target {
return true
}
if reflect.TypeOf(e) == tt {
return true
}
}
// return false
}
Expand Down

0 comments on commit d8fa44b

Please sign in to comment.