Skip to content

error-strings

Gostyleno fixdefault: offgo/revive

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.")).

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.

Reported
...
"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("")
go:
lint:
rules:
error-strings: warn # off (default), warn, error

Enabled by the presets: go/revive.

Suppress one line with sudsy-disable-next-line error-strings in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
revive error-strings full