Skip to content

errorf

Gostyleno fixdefault: offgo/revive

errors.New(fmt.Sprintf(...)) is fmt.Errorf(...) (the t.Error(fmt.Sprintf(...)) form on a *testing.T needs types and is not read).

fmt.Errorf formats and wraps (%w) in one call, and go vet knows its format string. errors.New(fmt.Sprintf(...)) formats a string first and then wraps it in an error, which is longer and cannot wrap another error with %w.

To fix, call fmt.Errorf with the same format and arguments.

Reported
package a
func f() {
_ = errors.New(fmt.Sprintf("x %d", 1))
_ = errors.New(fmt.Sprint("x"), 1)
_ = errors.New("x")
_ = fmt.Errorf("x %d", 1)
...
go:
lint:
rules:
errorf: warn # off (default), warn, error

Enabled by the presets: go/revive.

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