polyfloyd / go-errorlint

A source code linter that can be used to find code that will cause problems with Go's error wrapping scheme
MIT License
248 stars 19 forks source link

Unwrapping errors.Join error to []error through type assertion. #61

Closed forgoty closed 1 year ago

forgoty commented 1 year ago

I am trying to type assert multiples errors created with errors.Join

err := errors.Join(errors.New("err1"), errors.New("err2"))
errs, ok := err.(interface{ Unwrap() []error })

This code results in a warning:

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
        errs, ok := err.(interface{ Unwrap() []error })
                    ^

This is a valid case for me from go 1.20. Seems should be whitelisted.

polyfloyd commented 1 year ago

Fixed! Thanks for reporting :)