Skip to content

error-naming

Gostyleno fixdefault: offgo/revive

A package-level var of one name made by errors.New or fmt.Errorf starts with err, or Err when exported.

A package-level error variable is a sentinel that callers compare against with errors.Is, and it is read from other packages. The err and Err prefixes make such variables recognizable at the use site and keep the exported ones apart from other exported names. It is a Go convention; nothing breaks without it.

Reported
...
import "errors"
var failed = errors.New("x")
var Bad = errors.New("x")
var errOK = errors.New("x")
var ErrOK = fmt.Errorf("x")
var _ = errors.New("x")
var (
oops error = errors.New("x")
one, two = errors.New("x"), errors.New("y")
other = other()
)
...
go:
lint:
rules:
error-naming: warn # off (default), warn, error

Enabled by the presets: go/revive.

Suppress one line with sudsy-disable-next-line error-naming 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-naming full