Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,8 @@ func (st *stacktrace) ExitCode() int {
}
return int(st.code)
}

// Unwrap returns the cause of st.
func (st *stacktrace) Unwrap() error {
return st.cause
}
5 changes: 5 additions & 0 deletions stacktrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ func TestPropagateNil(t *testing.T) {

assert.Equal(t, stacktrace.NoCode, stacktrace.GetCode(err))
}

func TestUnwrap(t *testing.T) {
err := errors.New("cause")
assert.Equal(t, err, unwrap(stacktrace.Propagate(err, "propagated")))
}
9 changes: 9 additions & 0 deletions unwrap_1_13_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build go1.13

package stacktrace_test

import "errors"

func unwrap(err error) error {
return errors.Unwrap(err)
}
11 changes: 11 additions & 0 deletions unwrap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !go1.13

package stacktrace_test

func unwrap(err error) error {
t, ok := err.(interface{ Unwrap() error })
if !ok {
return nil
}
return t.Unwrap()
}