diff --git a/errors.go b/errors.go index 1c3c713..06e6f7e 100644 --- a/errors.go +++ b/errors.go @@ -33,3 +33,12 @@ func Cause(err error) error { } return err } + +// cause implements the interface required by Cause. +type cause struct { + err error +} + +func (c *cause) Cause() error { + return c.err +} diff --git a/errors_test.go b/errors_test.go index 86a53a5..b88e016 100644 --- a/errors_test.go +++ b/errors_test.go @@ -38,11 +38,10 @@ type nilError struct{} func (nilError) Error() string { return "nil error" } type causeError struct { - err error + cause } func (e *causeError) Error() string { return "cause error" } -func (e *causeError) Cause() error { return e.err } func TestCause(t *testing.T) { tests := []struct { @@ -66,7 +65,7 @@ func TestCause(t *testing.T) { want: io.EOF, }, { // caused error returns cause - err: &causeError{err: io.EOF}, + err: &causeError{cause{err: io.EOF}}, want: io.EOF, }}