{"record":{"id":"11cfbe500bd995bc","repo":"garrytan/gstack","slug":"excalidraw-scene-has-no-elements-array","errorCode":null,"errorMessage":"excalidraw scene has no elements array","messagePattern":"excalidraw scene has no elements array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/diagram-render/src/entry.ts","lineNumber":88,"sourceCode":"};\n\nwindow.__mermaidToExcalidraw = async (text: string): Promise<string> => {\n  const { elements, files } = await parseMermaidToExcalidraw(text);\n  const converted = convertToExcalidrawElements(elements);\n  const scene = {\n    type: \"excalidraw\",\n    version: 2,\n    source: \"gstack-diagram-render\",\n    elements: converted,\n    appState: { viewBackgroundColor: \"#ffffff\" },\n    files: files ?? {},\n  };\n  return JSON.stringify(scene);\n};\n\nwindow.__excalidrawToSvg = async (sceneJson: string): Promise<string> => {\n  const scene = JSON.parse(sceneJson);\n  if (!Array.isArray(scene.elements)) throw new Error(\"excalidraw scene has no elements array\");\n  const svg = await exportToSvg({\n    elements: scene.elements,\n    appState: { ...(scene.appState ?? {}), exportBackground: true },\n    files: scene.files ?? null,\n    exportPadding: 16,\n  });\n  return new XMLSerializer().serializeToString(svg);\n};\n\n/**\n * SVG → PNG data URL at an explicit pixel width. Callers own the DPI math:\n * targetWidthPx = placed physical width (in) × 300dpi (eng-review D6.5) —\n * the bundle never guesses a viewport.\n */\n/** Shared ceiling for rasterization targets (both window functions). */\nconst MAX_TARGET_PX = 10_000;\nfunction assertTargetWidth(px: number): void {\n  if (!(px > 0 && px <= MAX_TARGET_PX)) {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/lib/diagram-render/src/entry.ts#L70-L106","documentation":"Thrown by __excalidrawToSvg() when the parsed scene JSON does not have an Array at scene.elements. exportToSvg requires a real array of element objects, so a missing or wrongly-typed elements field would either throw deeper or render nothing; this guard fails early with a clear message. The function deliberately does not coerce — callers must pass a valid Excalidraw scene.","triggerScenarios":"Call window.__excalidrawToSvg(sceneJson) where sceneJson parses to an object whose elements is undefined, null, an object, a string, or absent entirely. Happens if the upstream __mermaidToExcalidraw output is mangled, a hand-built scene omits elements, or the wrong JSON is passed.","commonSituations":"Caller passes a mermaid text string instead of a scene object; a pipeline stage stripped elements during transformation; version-skew between the scene producer and this renderer; corrupted JSON.parse of a truncated payload.","solutions":["Validate the scene has elements as an array before calling — log the parsed object to inspect.","If producing scenes programmatically, always include elements: [...].","Ensure you are passing output from __mermaidToExcalidraw, not raw mermaid text.","If the payload was truncated in transit, re-serialize the full scene."],"exampleFix":"// before\n__excalidrawToSvg(JSON.stringify({ type: 'excalidraw' }));\n\n// after\n__excalidrawToSvg(JSON.stringify({ type: 'excalidraw', elements: [], appState: {}, files: {} }));","handlingStrategy":"type-guard","validationCode":"function assertExcalidrawScene(sceneJson: string): void {\n  const scene = JSON.parse(sceneJson);\n  if (!Array.isArray(scene.elements)) {\n    throw new Error('Pass a valid Excalidraw scene: { type, elements: [], appState, files }');\n  }\n}","typeGuard":"function isExcalidrawScene(v: unknown): v is { elements: unknown[]; [k: string]: unknown } {\n  return typeof v === 'object' && v !== null && Array.isArray((v as any).elements);\n}","tryCatchPattern":null,"preventionTips":["Only pass output of __mermaidToExcalidraw to __excalidrawToSvg.","Validate scene shape before serializing for transport.","Unit-test round-trip mermaid→excalidraw→svg to catch pipeline regressions.","Log the parsed scene when this fires to spot upstream changes."],"tags":["diagram-render","excalidraw","validation","json"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}