-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
bugIt is confirmed a bug, but don't worry, we'll handle it.It is confirmed a bug, but don't worry, we'll handle it.
Description
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?
What did you expect to see?
结果相反
这是复现示例代码:
package main
import (
"errors"
"github.com/gogf/gf/v2/errors/gerror"
pkgerror "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"testing"
)
var ErrNotFound = errors.New("not found")
func TestGerrorIs(t *testing.T) {
assert.True(t, pkgerror.Is(ErrNotFound, ErrNotFound), "pkg error 判断错误")
assert.True(t, errors.Is(ErrNotFound, ErrNotFound), "std error 判断错误")
assert.True(t, gerror.Is(ErrNotFound, ErrNotFound), "gerror 判断错误")
}
Metadata
Metadata
Assignees
Labels
bugIt is confirmed a bug, but don't worry, we'll handle it.It is confirmed a bug, but don't worry, we'll handle it.