Skip to content

Commit 915b0c8

Browse files
committed
fix(cli): a --budget that runs out before any check step is waiting is not an unhandled rejection
1 parent afbf945 commit 915b0c8

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎packages/cli/src/utils/checkDeadline.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class CheckDeadline {
8989
this.expiry = new Promise((_, reject) => {
9090
this.rejectExpiry = reject;
9191
});
92+
this.expiry.catch(() => undefined);
9293
this.budgetTimer =
9394
budget &&
9495
setTimeout(

‎packages/cli/src/utils/checkPipeline.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ async function withFindingCrops(
18481848
);
18491849
return { ...report, snapshots: { ...report.snapshots, findingFiles } };
18501850
} catch (error) {
1851-
if (error instanceof CheckDeadlineError || error instanceof CheckBudgetError) {
1851+
if (isCheckExpiry(error)) {
18521852
const finding = runtimeFailure(error);
18531853
return { ...report, ok: false, runtime: section([...report.runtime.findings, finding]) };
18541854
}
@@ -1882,11 +1882,7 @@ async function withOptionalFindingFrames(
18821882
const captured = await deadline.run(() => capture(project, options, requests, deadline));
18831883
return withFindingFrameFields(report, plan, captured);
18841884
} catch (error) {
1885-
if (
1886-
error instanceof CheckDeadlineError ||
1887-
error instanceof CheckStoppedError ||
1888-
error instanceof CheckBudgetError
1889-
) {
1885+
if (isCheckExpiry(error)) {
18901886
const finding = runtimeFailure(error);
18911887
return { ...report, ok: false, runtime: section([...report.runtime.findings, finding]) };
18921888
}
@@ -1896,6 +1892,11 @@ async function withOptionalFindingFrames(
18961892
}
18971893
}
18981894

1895+
const isCheckExpiry = (error: unknown): boolean =>
1896+
error instanceof CheckDeadlineError ||
1897+
error instanceof CheckStoppedError ||
1898+
error instanceof CheckBudgetError;
1899+
18991900
const MAX_FINDING_CROPS = 12;
19001901

19011902
/** Which error findings get a `finding-NN-<code>.png` crop for `check --snapshots`:

0 commit comments

Comments
 (0)