Skip to content

refactor: replace retry with internal async backoff retry loop#10663

Open
joehan wants to merge 1 commit into
mainfrom
joehan/remove-retry
Open

refactor: replace retry with internal async backoff retry loop#10663
joehan wants to merge 1 commit into
mainfrom
joehan/remove-retry

Conversation

@joehan

@joehan joehan commented Jun 15, 2026

Copy link
Copy Markdown
Member

Description

Removed the external third-party retry and @types/retry dependencies and replaced them with a native async retry loop with exponential backoff inside src/apiv2.ts.

Scenarios Tested

  • Run all src/apiv2.spec.ts unit tests successfully.

Sample Commands

  • npx mocha src/apiv2.spec.ts

### Description
Removed the external third-party `retry` and `@types/retry` dependencies and replaced them with a native async retry loop with exponential backoff inside `src/apiv2.ts`.

### Scenarios Tested
- Run all `src/apiv2.spec.ts` unit tests successfully.

### Sample Commands
- `npx mocha src/apiv2.spec.ts`

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request removes the external retry dependency and replaces its usage in src/apiv2.ts with a custom retry loop using a while (true) block and a sleep utility. The review feedback suggests avoiding the use of any in catch blocks to comply with the repository's TypeScript guidelines, and improving error wrapping in FirebaseError to preserve the original stack trace and error details.

Comment thread src/apiv2.ts
Comment on lines +435 to +436
} catch (thrown: any) {
const err = thrown instanceof Error ? thrown : new Error(thrown);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid using any as an escape hatch per the TypeScript guidelines in the repository style guide. We should type the caught variable as unknown and use a safe conversion to Error to ensure type safety.

Suggested change
} catch (thrown: any) {
const err = thrown instanceof Error ? thrown : new Error(thrown);
} catch (thrown: unknown) {
const err = thrown instanceof Error ? thrown : new Error(String(thrown));
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

Comment thread src/apiv2.ts
Comment on lines +479 to +481
} catch (err: unknown) {
throw err instanceof FirebaseError ? err : new FirebaseError(`${err}`);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

When wrapping a generic caught error in a FirebaseError, using new FirebaseError(${err}) converts the error to a string (which includes the error name, e.g., "Error: message") and discards the original stack trace.

Instead, we should check if the caught error is an instance of Error and pass it as the original property to preserve the stack trace and original error details.

      } catch (err: unknown) {
        if (err instanceof FirebaseError) {
          throw err;
        }
        if (err instanceof Error) {
          throw new FirebaseError(err.message, { original: err });
        }
        throw new FirebaseError(String(err));
      }

Comment thread src/apiv2.ts
} finally {
// If we succeed or failed, clear the timeout.
if (reqTimeout) {
clearTimeout(reqTimeout);
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.

3 participants