Skip to content

Show diagram errors as a callout - #223

Merged
MaggieAppleton merged 1 commit into
mainfrom
design/diagram-error
Sep 30, 2026
Merged

MaggieAppleton merged 1 commit into
mainfrom
design/diagram-error

Conversation

@MaggieAppleton

@MaggieAppleton MaggieAppleton commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces the bare red Mermaid error with a contained callout that says what went wrong in plain words and keeps the useful part of Mermaid's message.

Stacked on #218 (code block header bar). The callout sits inside that block's box, so this PR targets design/code-block. GitHub will retarget it to main when #218 merges.

Change

  • A failed diagram shows a pale red callout with a red warning icon in a disc, the title "This diagram could not be drawn", and a one-line reason.
  • The reason comes from a new, unit-tested describeDiagramError() in code.ts:
    • For an unknown diagram type, Mermaid echoes the whole source back after "for text:". The source is already on screen, so only "The diagram type is not recognised." is kept.
    • For a parse error, it shows "Parse error on line 3", the caret excerpt in monospace, and the "Expecting …" hint wrapped in the same type size and colour as the message.
    • Anything that matches no known shape falls back to Mermaid's own first line. An empty message gets a generic sentence.
  • Text uses --text-sm and --text-xs with their line-height tokens, and colours use theme tokens. The design contract passes with no new exceptions.
  • It is not a live region. The diagram re-renders on every keystroke while someone types, so an announcement would repeat constantly. KaTeX (math) errors keep their existing rendering.

Screenshots

Captured from the dev-only design audit page at 2x, with a parse-error diagram added temporarily to the audit to show that case.

Before (#218) After (this PR)
Diagram errors before Diagram errors after

Verification

After resolving the stack

The real editor still shows the parse-error explanation and unknown-diagram callout inside the updated code block.

Diagram error callouts after resolving conflicts

🤖 Generated with Claude Code

@MaggieAppleton
MaggieAppleton added this pull request to stack #227 September 30, 2026 11:04
Base automatically changed from design/code-block to main September 30, 2026 12:02
@MaggieAppleton
MaggieAppleton removed this pull request from stack #227 September 30, 2026 12:56
@MaggieAppleton
MaggieAppleton merged commit 9a5ac1d into main Sep 30, 2026
3 checks passed
@MaggieAppleton
MaggieAppleton deleted the design/diagram-error branch September 30, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant