Skip to content

Commit

Permalink
fix: Option to fail silently when retrying (#2015)
Browse files Browse the repository at this point in the history
Fixes #1783 
Add `failSilently` option to `retry` function. 
This means that nothing will be printed until we run out of retries, at
which point the error will be thrown.
  • Loading branch information
spypsy authored Sep 5, 2023
1 parent 114b43e commit 453c9c1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
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

0 comments on commit 453c9c1

Please sign in to comment.