From 9aa437c71f62a8d6f432ea8b7c1d339adaeb2df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pawlik?= Date: Thu, 11 Sep 2025 20:22:18 +0200 Subject: [PATCH] feat: Improve debug logging in retry logic (#1485) --- src/helpers.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 2b19ba1..92f29d0 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -185,15 +185,26 @@ export async function retryAndBackoff( return await fn(); } catch (err) { if (!isRetryable) { + core.debug(`retryAndBackoff: error is not retryable: ${errorMessage(err)}`); throw err; } // It's retryable, so sleep and retry. - await sleep(Math.random() * (2 ** retries * base)); - retries += 1; - if (retries >= maxRetries) { + const delay = Math.random() * (2 ** retries * base); + const nextRetry = retries + 1; + + core.debug( + `retryAndBackoff: attempt ${nextRetry} of ${maxRetries} failed: ${errorMessage(err)}. ` + + `Retrying after ${Math.floor(delay)}ms.`, + ); + + await sleep(delay); + + if (nextRetry >= maxRetries) { + core.debug('retryAndBackoff: reached max retries; giving up.'); throw err; } - return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base); + + return await retryAndBackoff(fn, isRetryable, maxRetries, nextRetry, base); } }