An analysis.Analyzer for error format strings: error
construction routes through fmt.Errorf, and error wrapping
routes through its %w verb.
errors.New can neither format nor wrap; fmt.Errorf does both,
is imported nearly everywhere already, and one error constructor
is simpler than two.
errors.New("connection lost") // errors.New can be replaced by fmt.ErrorfReported only: a message could contain a percent sign Errorf
would interpret, so the rewrite is the author's work.
An error value formatted into another error can be wrapped: %v
and %s verbs with error arguments become %w.
fmt.Errorf("open failed: %v", err) // error can be wrapped with %w, not %vThe fix rewrites the verb in place, and is withheld when the
format's source spelling differs from its value, as with escape
sequences. Only arguments whose static type is error are
considered, and only literal format strings are inspected. An
indexed or star verb makes the argument mapping non-positional and
skips the whole call.
go get -tool lesiw.io/errfmt/cmd/errfmt
go tool errfmt ./...