import { createRoot } from "react-dom/client"; import { recordBootFailure } from "../adapters/diagnostics/index.ts"; import { getBuildConfig } from "../contracts/env.ts"; import { BootErrorShell, type BootErrorShellProps, } from "../presentation/boundaries/boot-error-shell.tsx"; const ERROR_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]{0,39}$/u; /** * 09-04. A boot failure no loader classified: an assembly defect, a module * that threw while evaluating. It is shown as such, with the build and the * error's class name, never its message; a development build also reports * the original error to the console (`reportError`; direct console calls are * refused by check:diagnostics), where it was otherwise lost. */ export function unexpectedBootFailure(error: unknown): BootErrorShellProps { if (import.meta.env.DEV) globalThis.reportError?.(error); const { buildId } = getBuildConfig(); const name = error instanceof Error ? error.name : ""; const code = ERROR_NAME_PATTERN.test(name) ? name : "UNKNOWN_ERROR"; return Object.freeze({ kind: "BOOT_UNEXPECTED_FAILURE", code, buildId, supportReference: `${buildId}:BOOT_UNEXPECTED_FAILURE`, }); } /** * 09-03. Renders the boot failure when the application graph (boot.tsx) could * not even be evaluated. Nothing here reaches the installed feature graph, so * it still loads when that graph throws. */ export function renderBootFailure(error: unknown): void { const safe = unexpectedBootFailure(error); recordBootFailure(error, safe); const rootElement = document.getElementById("root"); if (!rootElement) throw error; createRoot(rootElement).render(); }