diff --git a/errors/context_map.go b/errors/context_map.go index 3455fa9..17d476e 100644 --- a/errors/context_map.go +++ b/errors/context_map.go @@ -77,3 +77,7 @@ func (c *withContext) FormatFields() string { } return buf.String() } + +func (c *withContext) Unwrap() error { + return c.cause +} diff --git a/errors/with_context_test.go b/errors/with_context_test.go index c31e33e..501f4c7 100644 --- a/errors/with_context_test.go +++ b/errors/with_context_test.go @@ -1,6 +1,7 @@ package errors_test import ( + "context" "fmt" "io" "strings" @@ -10,6 +11,8 @@ import ( "github.com/mailgun/holster/v4/callstack" "github.com/mailgun/holster/v4/errors" "github.com/stretchr/testify/assert" + + stderrors "errors" ) type TestError struct { @@ -68,3 +71,11 @@ func TestWrapNil(t *testing.T) { got := errors.WithContext{"some": "context"}.Wrap(nil, "no error") assert.Nil(t, got) } + +func TestUnwrap(t *testing.T) { + holsterWrappedErr := errors.WithContext{"some": "context"}.Wrap(context.Canceled, "external timeout") + assert.True(t, stderrors.Is(holsterWrappedErr, context.Canceled)) + + stdWrappedErr := fmt.Errorf("%w external timeout", context.Canceled) + assert.True(t, stderrors.Is(stdWrappedErr, context.Canceled)) +}