Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Option to fail silently when retrying #2015

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function makeFetch(retries: number[], noRetry: boolean, log?: DebugLogger
'JsonRpcClient request',
makeBackoff(retries),
log,
true,
);
};
}
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/foundation/src/retry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function* makeBackoff(retries: number[]) {
* @param name - The optional name of the operation, used for logging purposes.
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
* @param log - Logger to use for logging.
* @param failSilently - Do not log errors while retrying.
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
*/
Expand All @@ -48,6 +49,7 @@ export async function retry<Result>(
name = 'Operation',
backoff = backoffGenerator(),
log = createDebugLogger('aztec:foundation:retry'),
failSilently = false,
) {
while (true) {
try {
Expand All @@ -62,7 +64,7 @@ export async function retry<Result>(
throw err;
}
log(`${name} failed. Will retry in ${s}s...`);
log.error(err);
!failSilently && log.error(err);
await sleep(s * 1000);
continue;
}
Expand Down