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
cmd/vet: error when returning nil
inside an if err != nil
clause
#24141
Comments
err
inside an if err != nil
clauseerr
inside an if err != nil
clause
This seems like it will bring quite a few false positives. Have you prototyped such a change, and seen what it finds in the Go tree? |
Seems like the title should be "returning |
Here's a valid https://github.com/golang/go/blob/release-branch.go1.10/src/crypto/x509/root_darwin.go#L213-L225 |
This example is not what I suggest catching, because the if clause contains things other than |
Other reasonable scenarios come to mind, for example:
And there's also the can of worms that is errors that are always nil. This kind of check probably belongs in a tool that gives a human suggestions, and not a linter that gives warnings that must be accurate. |
err
inside an if err != nil
clausenil
inside an if err != nil
clause
Fails the precision criterion of cmd/vet/README. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?version 1.10
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?amd64, linux
What did you do?
I mistakenly return
nil
inside aif err != nil
clause, which hid a bug in my code. Since it almost never makes sense to returnnil
in such a case, I thought it'd be a nicego vet
error.func f() error {
err := ....
if err != nil {
return nil
}
return nil
}
The text was updated successfully, but these errors were encountered: