Skip to content

Commit c78cc95

Browse files
smiratalos-bot
authored andcommitted
fix: implement errors.Is for all errors in the set
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>
1 parent 7885e16 commit c78cc95

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

retry/retry.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ func (e *ErrorSet) Is(err error) bool {
9191
e.mu.Lock()
9292
defer e.mu.Unlock()
9393

94-
return len(e.errs) == 1 && errors.Is(e.errs[0], err)
94+
for _, ee := range e.errs {
95+
if errors.Is(ee, err) {
96+
return true
97+
}
98+
}
99+
100+
return false
95101
}
96102

97103
// TimeoutError represents a timeout error.

retry/retry_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ func Test_errors(t *testing.T) {
130130
t.Fatal("error set should wrap errors")
131131
}
132132

133+
errSet.Append(errors.New("foo"))
134+
135+
if !errors.Is(&errSet, e) {
136+
t.Fatal("error set should wrap errors")
137+
}
138+
133139
errSet = ErrorSet{}
134140
errSet.Append(UnexpectedError(e))
135141

0 commit comments

Comments
 (0)