{"record":{"id":"4cbbd98d1b13d06b","repo":"mermaid-js/mermaid","slug":"unknown-diagram-type-diagramtype","errorCode":null,"errorMessage":"Unknown diagram type: ${diagramType}","messagePattern":"Unknown diagram type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/parser/src/parse.ts","lineNumber":139,"sourceCode":"export async function parse(diagramType: 'architecture', text: string): Promise<Architecture>;\nexport async function parse(diagramType: 'gitGraph', text: string): Promise<GitGraph>;\nexport async function parse(diagramType: 'eventmodeling', text: string): Promise<EventModel>;\nexport async function parse(diagramType: 'radar', text: string): Promise<Radar>;\nexport async function parse(diagramType: 'railroad', text: string): Promise<Railroad>;\nexport async function parse(diagramType: 'railroadEbnf', text: string): Promise<RailroadEbnf>;\nexport async function parse(diagramType: 'railroadAbnf', text: string): Promise<RailroadAbnf>;\nexport async function parse(diagramType: 'railroadPeg', text: string): Promise<RailroadPeg>;\nexport async function parse(diagramType: 'treemap', text: string): Promise<Treemap>;\nexport async function parse(diagramType: 'wardley', text: string): Promise<Wardley>;\nexport async function parse(diagramType: 'cynefin', text: string): Promise<Cynefin>;\n\nexport async function parse<T extends DiagramAST>(\n  diagramType: keyof typeof initializers,\n  text: string\n): Promise<T> {\n  const initializer = initializers[diagramType];\n  if (!initializer) {\n    throw new Error(`Unknown diagram type: ${diagramType}`);\n  }\n  if (!parsers[diagramType]) {\n    await initializer();\n  }\n  const parser: LangiumParser = parsers[diagramType];\n  const result: ParseResult<T> = parser.parse<T>(text);\n  if (result.lexerErrors.length > 0 || result.parserErrors.length > 0) {\n    throw new MermaidParseError(result);\n  }\n  return result.value;\n}\n\nexport class MermaidParseError extends Error {\n  constructor(public result: ParseResult<DiagramAST>) {\n    const lexerErrors: string = result.lexerErrors\n      .map((err) => {\n        const line = err.line !== undefined && !isNaN(err.line) ? err.line : '?';\n        const column = err.column !== undefined && !isNaN(err.column) ? err.column : '?';","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/parser/src/parse.ts#L121-L157","documentation":"Thrown by parse() when diagramType is not a key of the `initializers` map (the registry of lazy diagram-parser factories). Each key (info, packet, pie, treeView, architecture, gitGraph, eventmodeling, radar, railroad, railroadEbnf, railroadAbnf, railroadPeg, treemap, wardley, cynefin) has an async initializer that loads its Langium parser on demand. An unrecognized type short-circuits before any parsing.","triggerScenarios":"Calling parse('flowchart', text) (flowchart isn't in this parser registry — it has its own), parse('sequence', text), or a typo like parse('Pie', text) (case-sensitive), parse('tree-view', text) (the key is 'treeView'), or parse('', text). Any diagramType not in the initializers keys throws.","commonSituations":"Mixing up the @mermaid-parser parse registry with mermaid's higher-level diagram registry (some diagrams like flowchart/sequence/state aren't Langium-parsed here), case or naming mismatches (kebab-case vs camelCase), or passing a user-supplied diagram type without validating.","solutions":["Pass one of the supported keys: info, packet, pie, treeView, architecture, gitGraph, eventmodeling, radar, railroad, railroadEbnf, railroadAbnf, railroadPeg, treemap, wardley, cynefin (exact case).","For flowchart/sequence/state/class/etc., use mermaid's main API rather than this low-level parse().","Validate diagramType against Object.keys(initializers) before calling parse.","Normalize user input (lowercase, camelCase) before lookup."],"exampleFix":"// before\nawait parse('tree-view', text); // wrong key, throws\n// after\nawait parse('treeView', text); // correct key","handlingStrategy":"validation","validationCode":"const KNOWN_TYPES = ['info','packet','pie','treeView','architecture','gitGraph','eventmodeling','radar','railroad','railroadEbnf','railroadAbnf','railroadPeg','treemap','wardley','cynefin'] as const;\nfunction isKnownDiagramType(t: string): boolean { return (KNOWN_TYPES as readonly string[]).includes(t); }\nif (!isKnownDiagramType(type)) throw new Error(`unsupported diagram type: ${type}`);","typeGuard":"function isDiagramType(t: unknown, known: readonly string[]): t is string { return typeof t === 'string' && known.includes(t); }","tryCatchPattern":"try { return await parse(type, text); } catch (e) { if (/Unknown diagram type/.test(String(e))) { throw new Error(`'${type}' is not a Langium-parsed diagram; use mermaid's main API`); } throw e; }","preventionTips":["Use the exact initializer keys (camelCase where applicable, e.g. 'treeView').","For flowchart/sequence/state, use mermaid's higher-level API, not this parse().","Normalize and validate user-supplied diagram types before lookup."],"tags":["parser","validation","diagram-type","registry"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}