Open
Conversation
There was a problem hiding this comment.
Found 1 issue in 1m 39s.
- src/utils/retry.ts:11 — The loop condition
attempt <= maxAttemptscauses the function to invokefn()a total ofmaxAttempts + 1times, notmaxAttempts. With the defaultmaxAttempts = 3, callers receive 4 call attempts instead of 3, violating the contract implied by the parameter name. The fix is to change the condition toattempt < maxAttempts. (issue)
There was a problem hiding this comment.
Found 1 issue in 1m 16s.
- src/utils/retry.ts:16 — The condition
if (attempt < maxAttempts)on line 16 is tautologically true because theforloop's own condition (attempt < maxAttempts) guaranteesattemptis always strictly less thanmaxAttemptswhile inside the loop body. The intended guard wasif (attempt < maxAttempts - 1), which would skip the sleep after the last attempt. As written, with the defaults ofmaxAttempts = 3andbaseDelayMs = 1000, callers always wait an unnecessary extra 4 seconds (1000 * 2² = 4000ms) after the final failure before the error is propagated. The fix is to change the condition toattempt < maxAttempts - 1. (issue)
There was a problem hiding this comment.
Found 1 issue in 2m 5s.
- src/utils/retry.ts:23 — When
maxAttemptsis0(or any non-positive value), theforloop body never executes, solastErrorstaysundefined. The subsequentthrow lastErrorstatement then throwsundefinedinstead of anError. Any caller that doescatch (err) { err.message }will receive a secondaryTypeError: Cannot read properties of undefined, and callers that docatch (err) { if (err instanceof Error) { ... } }will silently skip the error-handling branch. The fix is to guardthrow lastError— for example,throw lastError ?? new Error('retry called with maxAttempts <= 0')— or validate thatmaxAttempts >= 1at the top of the function. (issue)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Simple retry helper for wrapping flaky async operations.