Skip to content
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

Detect unchecked error within SimpleStmt of an IfStmt with error checking in conditional #1562

Open
dsnet opened this issue Jun 14, 2024 · 0 comments
Labels
aggressive A set of checks that is more prone to false positives but is helpful during code review new-check

Comments

@dsnet
Copy link
Contributor

dsnet commented Jun 14, 2024

(I'm aware of #1057, but I believe I'm reporting a particular unchecked error that has low false positives)

Consider a code that looks like the following:

if foo.WriteEntry(...); err != nil {
    ...
}

This is a bug, and the correct code should have been:

if err := foo.WriteEntry(...); err != nil {
    ...
}

I propose flagging the combination of:

  1. an unchecked error value in the SimpleStmt of the IfStmt
  2. an error check of some kind within the Expression of the IfStmt

Condition 2 almost certainly indicates a programmer's intent to do error checks, which should drastically reduce any false positives with condition 1.

@dsnet dsnet added false-negative needs-triage Newly filed issue that needs triage labels Jun 14, 2024
@dsnet dsnet changed the title Detect unchecked error Detect unchecked error within SimpleStmt of an IfStmt with error checking in conditional Jun 14, 2024
@dominikh dominikh added new-check aggressive A set of checks that is more prone to false positives but is helpful during code review and removed false-negative needs-triage Newly filed issue that needs triage labels Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aggressive A set of checks that is more prone to false positives but is helpful during code review new-check
Projects
None yet
Development

No branches or pull requests

2 participants