error-strings
What it does
Section titled “What it does”The text of an error made with fmt.Errorf, errors.New, errors.Errorf, errors.Wrap and the like ends in ., :, ! or a newline (a capital first letter is not reported). The text is the first argument, or the second of the functions that wrap an error (errors.Wrap(err, "failed.")).
Why it matters
Section titled “Why it matters”Error strings are joined into longer messages (failed to open: plus the cause), so a full stop, colon, exclamation mark or newline at the end leaves a doubled or dangling mark in the result and in logs. The Go code review comments ask for messages without end punctuation.
Example
Section titled “Example”... "fmt")
var a = errors.New("failed.")var b = fmt.Errorf("failed: %w", err)var c = fmt.Errorf("failed:")var d = errors.Wrap(err, "could not read!")var e = errors.New("line\n")var f = errors.New("Capitalized")var g = errors.New("quoted \\n")var h = errors.New(`raw.`)var i = errors.New(msg + ".")var j = log.Printf("failed.")var k = errors.New("")Configuration
Section titled “Configuration”go: lint: rules: error-strings: warn # off (default), warn, errorEnabled by the presets: go/revive.
Suppress one line with sudsy-disable-next-line error-strings in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| revive | error-strings |
full |