diff --git a/internal/xerrors/join.go b/internal/xerrors/join.go index 98fd95572..b5b29d683 100644 --- a/internal/xerrors/join.go +++ b/internal/xerrors/join.go @@ -43,3 +43,7 @@ func (errs joinError) Is(target error) bool { } return false } + +func (errs joinError) Unwrap() []error { + return errs +} diff --git a/internal/xerrors/join_test.go b/internal/xerrors/join_test.go index 186e9f24c..b970a3f61 100644 --- a/internal/xerrors/join_test.go +++ b/internal/xerrors/join_test.go @@ -4,6 +4,7 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -38,3 +39,15 @@ func TestJoin(t *testing.T) { }) } } + +func TestUnwrapJoined(t *testing.T) { + err1 := context.Canceled + err2 := context.DeadlineExceeded + + var joined error = Join(err1, err2) + + unwrappable := joined.(interface{ Unwrap() []error }) + inners := unwrappable.Unwrap() + assert.Contains(t, inners, err1) + assert.Contains(t, inners, err2) +}