retry-go icon indicating copy to clipboard operation
retry-go copied to clipboard

Attempts for error doesn't get considered when attempts is 0

Open bari-lb opened this issue 4 months ago • 0 comments

It seems that when using attempts=0, any value that's passed to attemptsForError is ignored in function DoWithData

If this is the intended design, shouldn't they be mutual exclusive? Warning? Panic? I suppose error is out of the question due to the api...

IMO it makes more sense to apply the logic of attemptsForError also when attempts=0, but whatever decided please document it. thanks.

Here's a link to playground that

https://go.dev/play/p/N4DaCm_UWcA

package main

import (
	"context"
	"fmt"
	"testing"
	"time"

	"github.com/avast/retry-go/v4"
)

func TestRetry(t *testing.T) {
	someFunc := func() error {
		fmt.Print("attempt\n")
		return context.Canceled
	}

	retry.Do(someFunc, retry.Delay(20*time.Millisecond), retry.AttemptsForError(1, context.Canceled))
	fmt.Print("work without infinite loop\n")
	retry.Do(someFunc, retry.Attempts(0), retry.Delay(20*time.Millisecond), retry.AttemptsForError(1, context.Canceled))
}

bari-lb avatar Sep 07 '25 07:09 bari-lb