-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errors/gerror: The judgment result of gerror's Is() method is a bit counter-intuitive #3633
Labels
bug
It is confirmed a bug, but don't worry, we'll handle it.
Comments
err1 := errors.New("permission denied")
fmt.Println(gerror.Is(err1, err1))// false
fmt.Println(gerror.Is(gerror.Wrap(err1, ""), err1))// 这样套一套能返回true,但有点多此一举
func Is(err, target error) bool {
if e, ok := err.(IIs); ok {
return e.Is(target)
}
return false // 这里不应该直接返回
} |
对的,同一个错误,Is都返回false,挺反直觉的 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go version
go version go1.22.3 windows/amd64
GoFrame version
2.7.1
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
这是gerror的源码部分:
func Is(err, target error) bool {
if e, ok := err.(IIs); ok {
return e.Is(target)
}
return false
}
由于标准库错误没有实现IIs接口,导致这里的判断直接变成false了。
参考下面的标准库的错误包 与 github.com/pkg/errors包的 判断对比。
What did you see happen?
我预期与标准库的errors.Is判断结果一致
What did you expect to see?
结果相反
这是复现示例代码:
The text was updated successfully, but these errors were encountered: