Skip to content

Commit

Permalink
Merge pull request #81 from JamieEdge/fix-80
Browse files Browse the repository at this point in the history
fix: reslice error log to remove nil values
  • Loading branch information
JaSei committed Jan 3, 2023
2 parents a297da9 + 56486ba commit e1515ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions retry.go
Expand Up @@ -157,7 +157,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
}
n++
errorLog[n] = config.context.Err()
return errorLog
return errorLog[:lenWithoutNil(errorLog)]
}

} else {
Expand All @@ -175,7 +175,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
if config.lastErrorOnly {
return errorLog[lastErrIndex]
}
return errorLog
return errorLog[:lenWithoutNil(errorLog)]
}

func newDefaultRetryConfig() *Config {
Expand Down
5 changes: 4 additions & 1 deletion retry_test.go
Expand Up @@ -31,6 +31,7 @@ func TestDoAllFailed(t *testing.T) {
#8: test
#9: test
#10: test`
assert.Len(t, err, 10)
assert.Equal(t, expectedErrorFormat, err.Error(), "retry error format")
assert.Equal(t, uint(45), retrySum, "right count of retry")
}
Expand Down Expand Up @@ -68,6 +69,7 @@ func TestRetryIf(t *testing.T) {
#1: test
#2: test
#3: special`
assert.Len(t, err, 3)
assert.Equal(t, expectedErrorFormat, err.Error(), "retry error format")
assert.Equal(t, uint(2), retryCount, "right count of retry")

Expand Down Expand Up @@ -164,7 +166,7 @@ func TestLastErrorOnly(t *testing.T) {
func TestUnrecoverableError(t *testing.T) {
attempts := 0
testErr := errors.New("error")
expectedErr := Error{testErr, nil}
expectedErr := Error{testErr}
err := Do(
func() error {
attempts++
Expand Down Expand Up @@ -367,6 +369,7 @@ func TestContext(t *testing.T) {
#1: test
#2: test
#3: context canceled`
assert.Len(t, err, 3)
assert.Equal(t, expectedErrorFormat, err.Error(), "retry error format")
assert.Equal(t, 2, retrySum, "called at most once")
})
Expand Down

0 comments on commit e1515ac

Please sign in to comment.