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)
.
x := "foobar"
return fmt.Errorf(x)
var callexpr = func() string { return "AJ1" }
return fmt.Errorf(callexpr())
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())