Error String Format
ID |
go.error_string_format |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Go |
Tags |
naming |
Description
Reports an error message built with errors.New(…) or fmt.Errorf(…) whose literal text
starts with an uppercase letter or ends with punctuation (., : or !).
Rationale
Go error strings are routinely wrapped and concatenated, for example
fmt.Errorf("open %s: %w", path, err). A capitalised or full-stopped fragment reads badly in
the middle of such a chained message, so the convention is lowercase, unpunctuated error text.
// Bad
errors.New("Something failed") // FLAW — leading uppercase
errors.New("connection refused.") // FLAW — trailing punctuation
// Good
errors.New("connection refused") // OK
fmt.Errorf("open %s: %w", p, err) // OK