mirror of
https://github.com/pkg/errors.git
synced 2025-05-31 11:42:45 +00:00
Added cause interface trait
This commit is contained in:
parent
ee5ece78bc
commit
4dd713cae9
@ -33,3 +33,12 @@ func Cause(err error) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cause implements the interface required by Cause.
|
||||||
|
type cause struct {
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cause) Cause() error {
|
||||||
|
return c.err
|
||||||
|
}
|
||||||
|
@ -38,11 +38,10 @@ type nilError struct{}
|
|||||||
func (nilError) Error() string { return "nil error" }
|
func (nilError) Error() string { return "nil error" }
|
||||||
|
|
||||||
type causeError struct {
|
type causeError struct {
|
||||||
err error
|
cause
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *causeError) Error() string { return "cause error" }
|
func (e *causeError) Error() string { return "cause error" }
|
||||||
func (e *causeError) Cause() error { return e.err }
|
|
||||||
|
|
||||||
func TestCause(t *testing.T) {
|
func TestCause(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -66,7 +65,7 @@ func TestCause(t *testing.T) {
|
|||||||
want: io.EOF,
|
want: io.EOF,
|
||||||
}, {
|
}, {
|
||||||
// caused error returns cause
|
// caused error returns cause
|
||||||
err: &causeError{err: io.EOF},
|
err: &causeError{cause{err: io.EOF}},
|
||||||
want: io.EOF,
|
want: io.EOF,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user