Go

Go

Made by DeepSource

Suspicious formatting of errors GO-W4017

Bug risk
Minor

If the argument to fmt.Errorf is not a constant value or a call expression (function, method) and the only argument; it is recommended to consider using errors.New with the same argument or pass the same along with "%s" to fmt.Errorf like fmt.Errorf("%s", arg).

Examples

Bad practice

x := "foobar"
return fmt.Errorf(x)
var callexpr = func() string { return "AJ1" }
return fmt.Errorf(callexpr())

Recommended

x := "foobar"
return errors.New(x) // or return fmt.Errorf("%s", x)
var callexpr = func() string { return "AJ1" }
return errors.New(callexpr()) // or return fmt.Errorf("%s", callexpr())