Skip to content

Commit 8bee8c9

Browse files
committed
fix(core): the runtime failure is recorded even when the thrown value cannot be printed
1 parent 71db155 commit 8bee8c9

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎packages/core/src/runtime/diagnostics.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ import { getDebugSurface } from "./globals.js";
3131

3232
/** The named error readiness waits fail with once start-up or a timeline post throws; it stays set. */
3333
export function recordStartupError(error: unknown): void {
34-
const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
34+
let detail = "unknown error";
35+
try {
36+
detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
37+
} catch (err) {
38+
swallow("runtime.startupError", err);
39+
}
3540
(window as Window & { __hfStartupError?: string }).__hfStartupError =
36-
`HyperFrames runtime failed: ${detail}. Fix the composition script or window.__timelines entry that threw.`;
41+
`HyperFrames runtime failed: ${detail}. Check the composition's scripts and window.__timelines ` +
42+
`entries; if they look right, report this as a HyperFrames bug.`;
3743
}
3844

3945
export function swallow(label: string, error?: unknown): void {

‎packages/core/src/runtime/entry.startupFailure.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,20 @@ describe("runtime start-up failure", () => {
4242

4343
await expect(evaluateRuntime()).rejects.toThrow("boom");
4444
expect(window.__hfStartupError).toContain("HyperFrames runtime failed: TypeError: boom");
45-
expect(window.__hfStartupError).toContain("Fix the composition script or window.__timelines entry");
45+
expect(window.__hfStartupError).toContain("Check the composition's scripts and window.__timelines");
46+
});
47+
48+
it("still records the failure when the thrown value cannot be printed", async () => {
49+
const thrown: unknown = Object.create(null);
50+
vi.doMock("./init", async (importOriginal) => ({
51+
...(await importOriginal<typeof import("./init")>()),
52+
initSandboxRuntimeModular: () => {
53+
throw thrown;
54+
},
55+
}));
56+
57+
await expect(evaluateRuntime()).rejects.toBe(thrown);
58+
expect(window.__hfStartupError).toContain("HyperFrames runtime failed: unknown error.");
4659
});
4760

4861
it("is not marked render-ready when posting the timeline throws", async () => {

0 commit comments

Comments
 (0)