Skip to content

Commit

Permalink
Add Unwrap for compat with go1.13 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Jul 13, 2020
1 parent 8a6fb52 commit 09e55f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions errwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,7 @@ func (w *wrappedError) Error() string {
func (w *wrappedError) WrappedErrors() []error {
return []error{w.Outer, w.Inner}
}

func (w *wrappedError) Unwrap() error {
return w.Inner
}
10 changes: 10 additions & 0 deletions errwrap_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package errwrap

import (
"errors"
"fmt"
"testing"
)
Expand Down Expand Up @@ -92,3 +93,12 @@ func TestGetAllType(t *testing.T) {
}
}
}

func TestWrappedError_IsCompatibleWithErrorsUnwrap(t *testing.T) {
inner := errors.New("inner error")
err := Wrap(errors.New("outer"), inner)
actual := errors.Unwrap(err)
if actual != inner {
t.Fatal("wrappedError did not unwrap to inner")
}
}

0 comments on commit 09e55f2

Please sign in to comment.