Reputation: 7165
https://github.com/golang/xerrors/blob/master/errors.go#L29:47
func (e *errorString) FormatError(p Printer) (next error) {
p.Print(e.s)
e.frame.Format(p)
return nil
}
If am not mistaken this always returns nil
right ? What is then the purpose of next
if it's always nil
?
Upvotes: 3
Views: 65
Reputation: 166714
What is then the purpose of next?
The FormatError(p Printer) (next error)
method satisfies an interface.
// A Formatter formats error messages.
type Formatter interface {
error
// FormatError prints the receiver's first error and returns the next error in
// the error chain, if any.
FormatError(p Printer) (next error)
}
Sometimes we do return a non-nil error.
func (e *noWrapError) FormatError(p Printer) (next error) {
p.Print(e.msg)
e.frame.Format(p)
return e.err
}
Upvotes: 2