Skip to content

Commit

Permalink
fix: implement errors.Is for all errors in the set
Browse files Browse the repository at this point in the history
Previously it matched only a single error if the set consists of a
single error. But the retry might fail many times on some expected error
followed by unexpected error which we want to test for with 'errors.Is'.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Jun 16, 2021
1 parent 7885e16 commit c78cc95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion retry/retry.go
Expand Up @@ -91,7 +91,13 @@ func (e *ErrorSet) Is(err error) bool {
e.mu.Lock()
defer e.mu.Unlock()

return len(e.errs) == 1 && errors.Is(e.errs[0], err)
for _, ee := range e.errs {
if errors.Is(ee, err) {
return true
}
}

return false
}

// TimeoutError represents a timeout error.
Expand Down
6 changes: 6 additions & 0 deletions retry/retry_test.go
Expand Up @@ -130,6 +130,12 @@ func Test_errors(t *testing.T) {
t.Fatal("error set should wrap errors")
}

errSet.Append(errors.New("foo"))

if !errors.Is(&errSet, e) {
t.Fatal("error set should wrap errors")
}

errSet = ErrorSet{}
errSet.Append(UnexpectedError(e))

Expand Down

0 comments on commit c78cc95

Please sign in to comment.