-
-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
staticcheck: detect error.Wrap
on nil
error
#529
Comments
I expected the |
Normally I am open to PRs, but not so much in this case. This check (and checks related to it) are something I want to actively experiment with myself. |
error.Wrap
on nil
errorerror.Wrap
on nil
error
Sounds good. Looking forward to checking it! |
It has been almost 5 years by now and this feature still appears to be missing. Any plans to finally check this? |
@JannikGM I switched to CodeQL for finding this specific issue. Check this query: https://github.com/github/codeql/blob/main/go/ql/src/InconsistentCode/WrappedErrorAlwaysNil.ql |
I don't think CodeQL works for us (license wise). I also tried to use CodeQL locally (for evaluation wether it might be worth it to purchase it) but couldn't even figure out how to use it. I'd definitely prefer a solution in staticcheck or golangci-lint. |
CodeQL is released under MIT license: https://github.com/github/codeql/blob/main/LICENSE |
That's only the queries, but not the engine and database tooling to use them (which is far more expensive and restrictive). From: https://github.com/github/codeql?tab=readme-ov-file#license
https://github.com/github/codeql-cli-binaries/blob/main/LICENSE.md |
github.com/pkg/errors
is a very popular package that provides helper methods for creating errors. One of the methods iserrors.Wrap(err error, message string) error
however, it's easy to forget that:Recently, while reviewing PRs by two different developers, I noticed a code like:
You can see that the second return always returns
nil
(to fix this, developer should useerrors.New
instead oferrors.Wrap
).Would be great to add a check that finds instances of this. I couldn't find any contribution guide, do you have any? Are you be willing to accept a PR with a new check? This is really connected to a single package so I wasn't sure you want to include such check.
The text was updated successfully, but these errors were encountered: