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

Don't fail if there is at least one error wrapping #5

Closed fkorotkov closed 4 years ago

fkorotkov commented 4 years ago

In our codebase we do wrap error to a generic internal error with code like this:

fmt.Errorf("%w: %v", ErrInternal, err)

The linter reports that the second error is not wrapped but that's fine.

polyfloyd commented 4 years ago

Yes, this seems like a valid usecase. Especially considering fmt.Errorf is able to only wrap one error at a time.

It might also be useful to add a check for multiple %w verbs in a single format string, but let's get this sorted out first.

polyfloyd commented 4 years ago

go vet does not like multiple %w verbs either, so the suggestion made by this linter is in conflict and therefore a bug

fkorotkov commented 4 years ago

Thank you for a speedy fix! 🎉