Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return unwrapping error when executing Do func #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Return unwrapping error when executing Do func
  • Loading branch information
zacscoding committed Oct 7, 2020
commit ac8584822681cb7e1d59a554ed0cf48f5c8a1389
2 changes: 1 addition & 1 deletion retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Do(ctx context.Context, b Backoff, f RetryFunc) error {

next, stop := b.Next()
if stop {
return err
return errors.Unwrap(err)
}

select {
Expand Down
17 changes: 17 additions & 0 deletions retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ func TestRetryableError(t *testing.T) {
func TestDo(t *testing.T) {
t.Parallel()

t.Run("unwrapping_error", func(t *testing.T) {
t.Parallel()

b := retry.BackoffFunc(func() (time.Duration, bool) {
return 1 * time.Nanosecond, true
})
cause := fmt.Errorf("oops")

ctx := context.Background()
err := retry.Do(ctx, retry.WithMaxRetries(1, b), func(_ context.Context) error {
return retry.RetryableError(cause)
})
if err != cause {
t.Errorf("expected %v to be %v", err, cause)
}
})

t.Run("exit_on_max_attempt", func(t *testing.T) {
t.Parallel()

Expand Down