Reliability and safety
errorownership
Checks that errors are handled once and classified structurally.
What it detects
Handle an error at one layer. The analyzer also catches inline error declarations whose condition accidentally checks a different error before returning the newly declared one.
Checks
| Check | What it detects |
|---|---|
log-and-return* |
Reports functions that both log and return the same error. |
text-classification |
Reports production code that classifies errors by matching their text. |
mismatched-inline-error |
Reports inline error declarations whose condition checks a different error. |
* Opt-in; requires explicit selection.
Why this is flagged
Handling the same error at several layers often creates duplicate logs or reports, while checking the wrong variable can silently ignore a real failure. Each layer should either add context and return the error or handle it fully.
How to fix it
Choose one responsibility at each layer: return the error with useful context,
or report and fully handle it there. When declaring an error inside an if,
make sure the condition checks that newly declared error.
Examples
Flagged code
func load() error { if err := readConfig(); err != nil { // gohawk: error is logged and returned by same function log.Print(err) return err } return nil}Accepted code
func loadWithContext() error { if err := readConfig(); err != nil { return fmt.Errorf("read config: %w", err) } return nil}