Skip to content

feat: add retry() helper - #2

Closed
NicholasZolton wants to merge 1 commit into
nicholas-variantfrom
demo-retry-util
Closed

NicholasZolton wants to merge 1 commit into
nicholas-variantfrom
demo-retry-util

Conversation

@NicholasZolton

Copy link
Copy Markdown
Collaborator

Adds a small retry() helper for flaky async operations. Opening this to watch the layered-review agent evaluate it against the repo's neverthrow rule (the helper uses try/catch + throw).

Comment thread src/util/retry.ts
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.

Comment thread src/util/retry.ts
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>.

@github-actions

Copy link
Copy Markdown

Layered Review

Error handling

  • ❌ src/util/retry.ts:5 (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.
  • ❌ src/util/retry.ts:11 (no-try-catch) — New thrown exception added. New fallible functions should return Result<T, E> from neverthrow using err(...)/ok(...) instead of throwing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant