Skip to content

Commit

Permalink
Merge pull request #85 from lizhiquan/fix-72
Browse files Browse the repository at this point in the history
fix: `IsRecoverable` should return false for wrapped unrecoverable
  • Loading branch information
JaSei authored Apr 21, 2023
2 parents 0407c19 + f85d915 commit b7892f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,13 @@ func Unrecoverable(err error) error {

// IsRecoverable checks if error is an instance of `unrecoverableError`
func IsRecoverable(err error) bool {
return !errors.Is(err, unrecoverableError{})
}

// Adds support for errors.Is usage on unrecoverableError
func (unrecoverableError) Is(err error) bool {
_, isUnrecoverable := err.(unrecoverableError)
return !isUnrecoverable
return isUnrecoverable
}

func unpackUnrecoverable(err error) error {
Expand Down
11 changes: 11 additions & 0 deletions retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,14 @@ func TestUnwrap(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, testError, errors.Unwrap(err))
}

func TestIsRecoverable(t *testing.T) {
err := errors.New("err")
assert.True(t, IsRecoverable(err))

err = Unrecoverable(err)
assert.False(t, IsRecoverable(err))

err = fmt.Errorf("wrapping: %w", err)
assert.False(t, IsRecoverable(err))
}

0 comments on commit b7892f8

Please sign in to comment.