An error is checked but not handled
What it finds
if err != nil {}: an error that is checked and then not handled is lost without a trace. Usually the handling was meant to be written later.
The variable must be named err or end in Err, the block must have no statements and there must be no else, since if err != nil {} else { ... } is a way, if an odd one, of handling the error. An error that is dropped on purpose reads better as _ = err with a comment that says why.
From the rule's source, empty_error_check.rs.
package p import "os" func f(name string) error { file, err := os.Open(name) if err != nil {tx0 reports: err is checked, but nothing handles it } if closeErr := file.Close(); nil != closeErr {tx0 reports: closeErr is checked } if err != nil { return err } if err != nil { } else { return nil } if err == nil { } if file != nil { } _ = os.Remove(name) return nil} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:empty-error-check" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:empty-error-check] reason="..."tx0 explain tx0/go:empty-error-check shows the same in the terminal. Found a false positive? Report it.