Skip to content

Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.

fix(import): report excessive Excalidraw JSON nesting (#415)

Rudy Mizrahi Celeklidd5ac3f7710d
diff --git a/scripts/verify-excalidraw-import.py b/scripts/verify-excalidraw-import.py
index 80cdb09..e4b29d4 100644
--- a/scripts/verify-excalidraw-import.py
+++ b/scripts/verify-excalidraw-import.py
@@ -723,6 +723,36 @@ def check_mobile_example() -> None:
ok("worked example is contained and locally scrollable at 390px")
+def check_json_nesting_diagnostic(tmp: Path) -> None:
+ source = tmp / "deeply-nested.excalidraw"
+ # Stay below the byte cap; JSON parser nesting limits vary across Python versions.
+ source.write_text(
+ '{"type":"excalidraw","elements":[],"appState":'
+ + "[" * 20000 + "0" + "]" * 20000 + "}",
+ encoding="utf-8",
+ )
+ successful_digests = []
+ for flags in ([], ["--json"]):
+ process = invoke([str(source), *flags])
+ if "Traceback" in process.stderr or "Traceback" in process.stdout:
+ fail("deeply nested JSON leaked a traceback")
+ if process.returncode == 2:
+ if "nesting exceeds the parser limit" not in process.stderr or process.stdout:
+ fail("deeply nested JSON lacked a nesting diagnostic or leaked a partial digest")
+ elif process.returncode == 0:
+ successful_digests.append((flags, process.stdout))
+ else:
+ fail(f"deeply nested JSON exited {process.returncode}: {process.stderr!r}")
+ source.write_text(scene("shallow-control", []), encoding="utf-8")
+ payload = json.loads(run_extract([str(source), "--json"]))
+ if payload["scene"]["nodes"] or payload["scene"]["edges"]:
+ fail("shallow JSON control unexpectedly changed the empty scene")
+ for flags, digest in successful_digests:
+ if digest != run_extract([str(source), *flags]):
+ fail("deeply nested JSON did not produce the normal empty-scene digest")
+ ok("deeply nested JSON imports or fails cleanly; shallow JSON still imports")
+
+
def check_unimported_container_text(tmp: Path) -> None:
source = tmp / "unsupported-container.excalidraw"
source.write_text(json.dumps({"type": "excalidraw", "elements": [
@@ -740,6 +770,7 @@ def main() -> int:
with tempfile.TemporaryDirectory(prefix="diagram-design-excalidraw-") as directory:
tmp = Path(directory)
check_files()
+ check_json_nesting_diagnostic(tmp)
check_unimported_container_text(tmp)
check_whiteboard()
check_bindings_and_shapes(tmp)
diff --git a/skills/diagram-design/references/import-excalidraw.md b/skills/diagram-design/references/import-excalidraw.md
index 6287ac9..a03dfdb 100644
--- a/skills/diagram-design/references/import-excalidraw.md
+++ b/skills/diagram-design/references/import-excalidraw.md
@@ -106,7 +106,7 @@ The extractor reports 10 IR nodes (8 drawable including 2 frames) and 6 edges; t
| Situation | Do |
|---|---|
| `.excalidraw.png` / `.excalidraw.svg` export | The extractor rejects it by design. Ask for the saved `.excalidraw` scene; don't scrape pixels. |
-| Extractor exits 2 | Report the message verbatim — it names the actual problem (not Excalidraw JSON / no elements / over limits). Don't fall back to reading the raw file. |
+| Extractor exits 2 | Report the message verbatim — it names the actual problem (not Excalidraw JSON / no elements / over limits / JSON nesting exceeds the parser limit). Don't fall back to reading the raw file. |
| `edges_dangling > 0` | Arrows whose bindings were deleted or never attached. Omit them from the redraw, but record the count in the fidelity ledger and call out any labeled or otherwise meaningful loss. |
| Unconnected nodes listed | Usually sticky notes, titles, or abandoned boxes. Drop unless the label says otherwise; mention in the ledger if it looked meaningful. |
| Labels are empty across the board | The sketch carries meaning in position only. Ask the user what the boxes are — don't invent names. |
diff --git a/skills/diagram-design/scripts/excalidraw_extract.py b/skills/diagram-design/scripts/excalidraw_extract.py
index c6386fa..6b57876 100644
--- a/skills/diagram-design/scripts/excalidraw_extract.py
+++ b/skills/diagram-design/scripts/excalidraw_extract.py
@@ -182,6 +182,8 @@ def load_scene_data(path: Path) -> dict[str, Any]:
f"invalid geometry: {token} is not finite"
),
)
+ except RecursionError:
+ _fail(f"{path.name}: Excalidraw JSON nesting exceeds the parser limit")
except (UnicodeDecodeError, ValueError):
_fail(f"{path.name}: not valid Excalidraw JSON")
if not isinstance(document, dict) or document.get("type") != "excalidraw":