diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..921b870 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/palantir/stacktrace + +go 1.14 + +require github.com/stretchr/testify v1.5.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..331fa69 --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/stacktrace.go b/stacktrace.go index 324c4bc..f1fbd47 100644 --- a/stacktrace.go +++ b/stacktrace.go @@ -247,3 +247,8 @@ func (st *stacktrace) ExitCode() int { } return int(st.code) } + +// Unwrap implements Go 1.13 error unwrapping +func (st *stacktrace) Unwrap() error { + return RootCause(st) +} diff --git a/stacktrace_test.go b/stacktrace_test.go index c1276f2..27c5e09 100644 --- a/stacktrace_test.go +++ b/stacktrace_test.go @@ -98,3 +98,9 @@ func TestPropagateNil(t *testing.T) { assert.Equal(t, stacktrace.NoCode, stacktrace.GetCode(err)) } + +func TestGo113Unwrap(t *testing.T) { + rootCause := errors.New("root cause") + err := stacktrace.Propagate(rootCause, "") + assert.True(t, errors.Is(err, rootCause)) +}