Skip to content

Commit

Permalink
Merge pull request #74 from KeiichiHirobe/fix-overwrite-error
Browse files Browse the repository at this point in the history
fix bug that overwrites last error when context is canceled
  • Loading branch information
JaSei authored Nov 15, 2022
2 parents f0085d2 + 0835d1a commit f8ec78f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
if config.lastErrorOnly {
return config.context.Err()
}
n++
errorLog[n] = config.context.Err()
return errorLog
}
Expand Down
3 changes: 2 additions & 1 deletion retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ func TestContext(t *testing.T) {

expectedErrorFormat := `All attempts fail:
#1: test
#2: context canceled`
#2: test
#3: context canceled`
assert.Equal(t, expectedErrorFormat, err.Error(), "retry error format")
assert.Equal(t, 2, retrySum, "called at most once")
})
Expand Down

0 comments on commit f8ec78f

Please sign in to comment.