cmd/vet: should check for missing call to "Err() error" methods #17747
Labels
Milestone
Comments
There are legitimate cases in which you might elide the s.Err check, such as when reading lines from a
How frequently is frequently? How bad are the resulting bugs? cc @robpike |
It probably comes up in code review at least once or twice per week. Typically when interacting with a database. As far as the severity of the resulting bugs, I am not sure. I'm on a different team and often just get asked to do code review sporadically, even though I typically don't maintain the projects where these problems occur. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/zvrWRVgw4M
Used a
bufio.Scanner
without checkingbufio.Scanner.Err()
for error. The same mistake occurs frequently withsql.Rows.Err()
.What did you expect to see?
go vet
should warn thats.Err()
was not called, and that it should be checked to determine if an error occurred while scanning.This frequently occurs in our internal codebase at work. Arguably,
go vet
could check if any type has a methodErr() error
and report if the error is not checked or returned, instead of just checking the special cases withbufio.Scanner
andsql.Rows
. There may also be more types that use this pattern in the standard library.What did you see instead?
No warnings from
go vet
.The text was updated successfully, but these errors were encountered: