Skip to content

Commit

Permalink
Fix calling fmt.Errorf to join multiple errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendc committed Nov 1, 2024
1 parent b571f04 commit 4215a05
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ import (
"github.com/stretchr/testify/assert"
)

type wrappedErrs struct { //nolint:errname
errs []error
}

func (we *wrappedErrs) Error() string {
return ""
}

func (we *wrappedErrs) Unwrap() []error {
return we.errs
}

func Test_ErrUnwrap(t *testing.T) {
e1 := errors.New("e1")
e2 := fmt.Errorf("e2: %w", e1)
e3 := fmt.Errorf("e3: %w - %w", e1, e2) // NOTE: errors.Join() is unavailable in Go prior to 1.20
e3 := &wrappedErrs{errs: []error{e1, e2}}

assert.Equal(t, []error(nil), ErrUnwrap(nil))
assert.Equal(t, []error(nil), ErrUnwrap(e1))
Expand Down

0 comments on commit 4215a05

Please sign in to comment.