mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
fix: don't use re-pointer
This commit is contained in:
parent
37ceb66f7a
commit
2f4223ed12
@ -15,7 +15,7 @@ func NewWrappedError(err, cause error) error {
|
||||
}
|
||||
|
||||
func (e *wrappedError) As(target interface{}) bool {
|
||||
return errors.As(e.err, &target) || errors.As(e.cause, &target)
|
||||
return errors.As(e.err, target) || errors.As(e.cause, target)
|
||||
}
|
||||
|
||||
func (e *wrappedError) Is(target error) bool {
|
||||
|
||||
@ -13,9 +13,20 @@ var (
|
||||
ErrTwo = errors.New("two")
|
||||
)
|
||||
|
||||
type ErrThree struct {
|
||||
error
|
||||
}
|
||||
|
||||
func (e *ErrThree) Foo() string {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
func main() {
|
||||
err1 := ErrOne
|
||||
err2 := keelerrors.NewWrappedError(err1, ErrTwo)
|
||||
err3 := &ErrThree{error: errors.New("error three")}
|
||||
err4 := keelerrors.NewWrappedError(err3, ErrTwo)
|
||||
err5 := keelerrors.NewWrappedError(ErrTwo, err3)
|
||||
|
||||
if errors.Is(err1, ErrOne) {
|
||||
fmt.Println("err1 = ErrOne") //nolint:forbidigo
|
||||
@ -26,4 +37,22 @@ func main() {
|
||||
if errors.Is(err2, ErrOne) {
|
||||
fmt.Println("err2 = ErrOne") //nolint:forbidigo
|
||||
}
|
||||
{
|
||||
var foo *ErrThree
|
||||
if errors.As(err3, &foo) {
|
||||
fmt.Println("err3 = ErrThree (" + foo.Foo() + ")") //nolint:forbidigo
|
||||
}
|
||||
}
|
||||
{
|
||||
var foo *ErrThree
|
||||
if errors.As(err4, &foo) {
|
||||
fmt.Println("err4 = ErrThree (" + foo.Foo() + ")") //nolint:forbidigo
|
||||
}
|
||||
}
|
||||
{
|
||||
var foo *ErrThree
|
||||
if errors.As(err5, &foo) {
|
||||
fmt.Println("err5 = ErrThree (" + foo.Foo() + ")") //nolint:forbidigo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user