gerror: fix #3633 Is performs the same as errors.Is from go stdlib (#3640)

This commit is contained in:
John Guo
2024-06-13 21:55:32 +08:00
committed by GitHub
parent ffbe9a7197
commit 74d0945fa1
5 changed files with 29 additions and 35 deletions

View File

@ -7,6 +7,7 @@
package gerror
import (
"errors"
"runtime"
)
@ -91,17 +92,17 @@ func Equal(err, target error) bool {
}
// Is reports whether current error `err` has error `target` in its chaining errors.
// It is just for implements for stdlib errors.Is from Go version 1.17.
// There's similar function HasError which is designed and implemented early before errors.Is of go stdlib.
// It is now alias of errors.Is of go stdlib, to guarantee the same performance as go stdlib.
func Is(err, target error) bool {
if e, ok := err.(IIs); ok {
return e.Is(target)
}
return false
return errors.Is(err, target)
}
// HasError is alias of Is, which more easily understanding semantics.
// HasError performs as Is.
// This function is designed and implemented early before errors.Is of go stdlib.
// Deprecated: use Is instead.
func HasError(err, target error) bool {
return Is(err, target)
return errors.Is(err, target)
}
// callers returns the stack callers.