Skip to content

Commit ee07a65

Browse files
committed
fix(release): drop unused lastError initializer in brew tarball poll
CodeQL flagged the dummy Error assigned before the fetch loop: every path overwrites it, so the initial object was dead. Keep lastError unset until a real fetch failure, and fall back only if the loop exits without one.
1 parent 92c1595 commit ee07a65

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎scripts/release/update-brew-formula.mjs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function downloadNpmTarball(options) {
2727
const { url, fetchImpl, sleep, now, budgetMs, intervalMs, log = console.log } = options;
2828
const deadline = now() + budgetMs;
2929
let attempts = 0;
30-
let lastError = new Error('Failed to download npm tarball');
30+
let lastError;
3131

3232
for (;;) {
3333
attempts += 1;
@@ -44,10 +44,11 @@ export async function downloadNpmTarball(options) {
4444
lastError = new Error(`Failed to download npm tarball: ${errorMessage(error)}`, { cause: error });
4545
}
4646

47+
const message = lastError?.message ?? 'Failed to download npm tarball';
4748
if (now() + intervalMs >= deadline) {
48-
throw new Error(`${lastError.message} after ${attempts} attempt(s)`);
49+
throw new Error(`${message} after ${attempts} attempt(s)`);
4950
}
50-
log(`${lastError.message} (attempt ${attempts}); retrying in ${intervalMs / 1000}s`);
51+
log(`${message} (attempt ${attempts}); retrying in ${intervalMs / 1000}s`);
5152
await sleep(intervalMs);
5253
}
5354
}

0 commit comments

Comments
 (0)