Skip to content

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

@bari-lb

Description

@bari-lb

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))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions