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
249 stars 19 forks source link

Disable comparison linter for `errors.Cause(err) != sql.ErrNoRows` expression #18

Closed etuseeva closed 3 years ago

etuseeva commented 3 years ago

Hello! In our codebase a lot of such code:

...
if errors.Cause(err) != sql.ErrNoRows {
   ...
}
...

And comparison linter complains about that:

comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
if errors.Cause(err) != sql.ErrNoRows {

This is incorrect, since errors.Cause(err) != sql.ErrNoRows is similar to !errors.Is(err, sql.ErrNoRows), isn't it?

So is there a way to turn it off? Or is it a bug?

Thanks!

polyfloyd commented 3 years ago

There is no errors.Cause in the Go's standard library. Do you happen to be using this third party library?

This linter is intended to be used with the Go's errors library. So your options are: