Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/util/retry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** Retry a flaky async operation a few times before giving up. */
export async function retry<T>(fn: () => Promise<T>, attempts = 3): Promise<T> {
let lastError: unknown
for (let i = 0; i < attempts; i++) {
try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Error handling / no-try-catch

New try/catch block added in a new file. The codebase is migrating to neverthrow; new fallible code should return Result<T, E> instead of using try/catch.

Suggested fix: Refactor to accept a function returning ResultAsync<T, E> and use .orElse() for retries instead of try/catch.

return await fn()
} catch (e) {
lastError = e
}
}
throw new Error(`retry failed after ${attempts} attempts: ${String(lastError)}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Error handling / no-try-catch

New thrown exception added. New fallible functions should return Result<T, E> from neverthrow using err(...)/ok(...) instead of throwing.

Suggested fix: Return err(...) from neverthrow and update the function signature to return Result<T, E> or ResultAsync<T, E>.

}
Loading