Yes. Relying on fmt.Errorf
and %w
appear to be a more practical pattern when you don’t need to be able to match both the “inner” and “outer” type, which usually you don’t.
Also not sure the Is
implementation is really to relevant. Nowadays, I would probably write a const
string-based error with only an Error
function, and rely on fmt.Errorf
like you describe.
package mypkgtype strError stringfunc (err strError) Error() string {
return string(err)
}const (
ErrFoo = strError("foo")
)