Overview
Mermaid provides comprehensive error handling mechanisms to help you identify and resolve issues with diagram syntax, rendering, and configuration. This guide covers error detection, handling strategies, and debugging techniques.Error types
UnknownDiagramError
Thrown when Mermaid cannot detect the diagram type (errors.ts:1):
Parse errors
Parse errors occur when diagram syntax is invalid. These are caught during the parsing phase.Render errors
Render errors happen during diagram rendering and may be caused by configuration issues or browser limitations.The parse function
Usemermaid.parse() to validate diagram syntax without rendering (mermaidAPI.ts:67):
Basic validation
Suppressing errors
UsesuppressErrors: true to return false instead of throwing:
Examples from source
Frommermaid.ts:336:
Error handling in render
The render function provides built-in error handling (mermaidAPI.ts:392):
Suppress error rendering
Control whether error diagrams are displayed:Custom error handlers
Setting a parse error handler
Set a global error handler for parse errors (mermaid.ts:304):
DetailedError interface
Mermaid provides detailed error information:Error handling in run()
Therun() function handles errors from multiple diagrams (mermaid.ts:64):
Using suppressErrors in run()
When rendering multiple diagrams withmermaid.run(), suppress errors to continue processing:
mermaid.ts:109:
Debugging techniques
Enable debug logging
'fatal', 'error', 'warn', 'info', 'debug', 'trace'
Check diagram type detection
Verify which diagram type Mermaid detects:Validate before rendering
1
Parse the diagram
2
Check validation result
3
Render the diagram
Common errors and solutions
Text size exceeded
Error:Maximum text size in diagram exceeded
Cause: Diagram text exceeds maxTextSize limit (default: 50,000 characters)
Solution:
Unknown diagram type
Error:UnknownDiagramError: No diagram type detected
Cause: The diagram syntax doesn’t match any registered diagram type
Solutions:
- Check the diagram keyword (e.g.,
flowchart,sequenceDiagram) - Ensure the diagram type is registered
- Remove comments and directives that may interfere with detection
Parse errors with directives
Error: Parse fails with%%init%% directive
Cause: Directive syntax is incorrect
Solution: