Skip to content

Commit

Permalink
Merge pull request #858 from MaxShoshin/patch-1
Browse files Browse the repository at this point in the history
Allow to unwrap joined errors
  • Loading branch information
asmyasnikov authored Nov 4, 2023
2 parents c5cd3f1 + aff378f commit d98f854
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/xerrors/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ func (errs joinError) Is(target error) bool {
}
return false
}

func (errs joinError) Unwrap() []error {
return errs
}
13 changes: 13 additions & 0 deletions internal/xerrors/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -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 })

Check failure on line 49 in internal/xerrors/join_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
inners := unwrappable.Unwrap()
assert.Contains(t, inners, err1)
assert.Contains(t, inners, err2)
}

0 comments on commit d98f854

Please sign in to comment.