-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: cmd/go: run the errors.As vet check as part of go test
#31213
Comments
go test
go test
Is there a way to get more data on how often this occurs? Also can we make this more reliable by ignoring the empty interface like in your example above? |
Unfortunately not, until 1.13 is in general use.
I did this in https://go-review.googlesource.com/c/tools/+/175717. |
This is analogous to the existing json.Unmarshal/xml.Unmarshal checks; we know that was a common mistake for those. It tends not to get into production code, although here it might be even more likely. The check is also cheap. Now that we've decided to add errors.As for Go 1.13, accepting this proposal as well. |
Re:
we should probably look into what the json.Unmarshal check does, and do the same. (I would expect this code is OK.) |
The json.Unmarshal check doesn't report a problem if the argument is an interface type (any interface type). Even with the above PR, this check is stricter: it won't report on
|
Change https://golang.org/cl/179977 mentions this issue: |
Change https://golang.org/cl/181717 mentions this issue: |
This change revendors golang.org/x/tools to include the check and modifies cmd/vet to add it to the command. CL 179977 will enable the check by default for 'go test'. Commands run (starting in GOROOT/src): cd cmd emacs vet/main.go go get -u=patch golang.org/x/tools/go/analysis/passes/errorsas@latest go mod tidy go mod vendor cd .. ./make.bash go test all Updates #31213 Change-Id: Ic2ba9bd2d31c4c5fd9e7c42ca14e8dc38520c93b Reviewed-on: https://go-review.googlesource.com/c/go/+/181717 Reviewed-by: Jonathan Amsterdam <jba@google.com>
This new vet check validates that the second argument to
errors.As
is a pointer to an interface or a type implementing error.It can generate a false positive if a valid value is held in a different static type, such as
but that's unlikely.
The text was updated successfully, but these errors were encountered: