Files
hyperframes/packages/cli/src/utils/errorMessage.ts
T
Miguel Ángel 1bc4bd9ca4 fix(cli): a check or snapshot that times out says which step it was on (#6531)
* fix(cli): a check or snapshot that times out says which step it was on

check's idle deadline named only the phase ("while checking samples") and snapshot's
CDP timeout named nothing. check now adds the sample, craft frame or overlap probe it
was on, and snapshot adds the seek or capture of the frame it was on, with its time.

* fix(cli): a snapshot timeout no longer tells the user to raise a setting they do not have

Puppeteer's protocol timeout message ends "Increase the 'protocolTimeout' setting in
launch/connect calls". snapshot has no such option, so the step it was on is now the
last thing the message says.
2026-10-27 08:16:01 +00:00

33 lines
1.0 KiB
TypeScript

export function normalizeErrorMessage(error: unknown): string {
if (error instanceof Error) return error.message;
if (typeof error === "string") return error;
if (typeof error === "object" && error !== null) {
const msg = (error as Record<string, unknown>).message;
if (typeof msg === "string") return msg;
try {
return JSON.stringify(error) ?? `{${Object.keys(error).join(", ")}}`;
} catch {
try {
return `{${Object.keys(error as object).join(", ")}}`;
} catch {
/* truly opaque object */
}
}
}
return String(error ?? "unknown error");
}
const PROTOCOL_TIMEOUT_ADVICE =
/ Increase the 'protocolTimeout' setting in launch\/connect calls[^.]*\./;
export async function atStep<T>(step: string, run: () => Promise<T>): Promise<T> {
try {
return await run();
} catch (error) {
if (error instanceof Error && !error.message.includes(` (while ${step})`)) {
error.message = error.message.replace(PROTOCOL_TIMEOUT_ADVICE, "") + ` (while ${step})`;
}
throw error;
}
}