Merge pull request #1436 from kaitranntt/codex/fix-null-retryablecheck-crash

fix: tolerate null retryable check
This commit is contained in:
Kai (Tam Nhu) Tran authored and GitHub committed 2026-05-30 15:46:21 -04:00
commit 229d5456c2
2 files changed
+21 -1

No files matched your search

@@ -25,6 +25,26 @@ describe('withRetry', () => {
expect(fn).toHaveBeenCalledTimes(3);
});
it('uses the default retryability check when retryableCheck is null at runtime', async () => {
let attempt = 0;
const fn = mock(() => {
attempt++;
if (attempt < 2) {
return Promise.reject(new RetryableError('transient failure'));
}
return Promise.resolve('ok');
});
const result = await withRetry(fn, {
maxRetries: 3,
baseDelayMs: 1,
retryableCheck: null,
} as unknown as RetryOptions);
expect(result).toBe('ok');
expect(fn).toHaveBeenCalledTimes(2);
});
it('throws after max retries exhausted', async () => {
const fn = mock(() => Promise.reject(new RetryableError('always fails')));
await expect(withRetry(fn, { maxRetries: 2, baseDelayMs: 1 })).rejects.toThrow('always fails');
+1 -1
View File
@@ -99,7 +99,7 @@ export async function withRetry<T>(fn: () => Promise<T>, options: RetryOptions):
throw new Error('withRetry: baseDelayMs must be >= 0');
}
const isRetryable = retryableCheck;
const isRetryable = retryableCheck ?? defaultRetryableCheck;
let lastError: unknown;
for (let attempt = 0; attempt <= maxRetries; attempt++) {