From fefa5f81e90586153f708b14c9379f38ea47d68e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Sun, 24 Mar 2024 18:22:54 +0100 Subject: [PATCH] `retry`: Reduce `nil` checks for errors Before, with `Timeout >0`, we had to check errors for `nil` because we were using a deadline context that might have cancelled before the retry function completed with an error, but since we now pass `ctx` as-is, this is no longer necessary. --- pkg/retry/retry.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pkg/retry/retry.go b/pkg/retry/retry.go index a0b55c3c4..48ac4f008 100644 --- a/pkg/retry/retry.go +++ b/pkg/retry/retry.go @@ -79,18 +79,11 @@ func WithBackoff( select { case <-time.After(b(attempt)): case <-timeout: - if err != nil { - err = errors.Wrap(err, "retry deadline exceeded") - } else { - err = errors.New("retry deadline exceeded") - } + err = errors.Wrap(err, "retry deadline exceeded") return case <-ctx.Done(): - if err == nil { - err = ctx.Err() - } - err = errors.Wrap(err, "can't retry") + err = errors.Wrap(err, ctx.Err().Error()) return }