1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-10-18 14:24:20 +00:00
go_helpers/backoff/error.go
Knut Ahlers 8991a9232b
Add special error to terminate retries immediately
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2023-11-27 23:11:44 +01:00

25 lines
641 B
Go

package backoff
import "fmt"
type (
// ErrCannotRetry wraps the original error and signals the backoff
// should be stopped now as a retry i.e. would be harmful or would
// make no sense
ErrCannotRetry struct{ inner error }
)
// NewErrCannotRetry wraps the given error into an ErrCannotRetry and
// should be used to break from a Retry() function when the retry
// should stop immediately
func NewErrCannotRetry(err error) error {
return ErrCannotRetry{err}
}
func (e ErrCannotRetry) Error() string {
return fmt.Sprintf("retry cancelled by error: %s", e.inner.Error())
}
func (e ErrCannotRetry) Unwrap() error {
return e.inner
}