{"record":{"id":"6b1917394dd30389","repo":"mermaid-js/mermaid","slug":"edges-array-is-required-in-layout-data","errorCode":null,"errorMessage":"Edges array is required in layout data","messagePattern":"Edges array is required in layout data","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid-layout-tidy-tree/src/layout.ts","lineNumber":649,"sourceCode":" * Validate layout data structure\n * @param data - The data to validate\n * @returns True if data is valid, throws error otherwise\n */\nexport function validateLayoutData(data: LayoutData): boolean {\n  if (!data) {\n    throw new Error('Layout data is required');\n  }\n\n  if (!data.config) {\n    throw new Error('Configuration is required in layout data');\n  }\n\n  if (!Array.isArray(data.nodes)) {\n    throw new Error('Nodes array is required in layout data');\n  }\n\n  if (!Array.isArray(data.edges)) {\n    throw new Error('Edges array is required in layout data');\n  }\n\n  return true;\n}\n","sourceCodeStart":631,"sourceCodeEnd":654,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid-layout-tidy-tree/src/layout.ts#L631-L654","documentation":"Thrown by validateLayoutData when data.edges is present but not an array. Note executeTidyTreeLayout tolerates missing/non-array edges by defaulting them to [], so this validator is stricter than the layout entry point and exists for callers that want guaranteed-correct shapes.","triggerScenarios":"Passing data.edges as an object, a single edge, or any non-array value while still calling the strict validator.","commonSituations":"Producer modeled edges as a keyed object and forwarded it; a serialization step left edges as a string; defensive validation turned on before the layout call.","solutions":["Coerce edges to an array: Object.values(edges) or [] when none exist.","Use Array.isArray(edges) at the producer and convert before assembling LayoutData.","If you do not need strict validation, skip validateLayoutData and rely on executeTidyTreeLayout's lenient defaulting."],"exampleFix":"// before\nvalidateLayoutData({ nodes, edges: edgesRecord, config });\n\n// after\nvalidateLayoutData({ nodes, edges: Object.values(edgesRecord), config });","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(data.edges)) {\n  data.edges = [];\n}\nvalidateLayoutData(data);","typeGuard":"function hasEdgeArray(data: unknown): data is { edges: unknown[] } {\n  return Array.isArray((data as any).edges);\n}","tryCatchPattern":null,"preventionTips":["Default edges to [] when assembling LayoutData.","Coerce record/object edge stores to arrays at the producer boundary."],"tags":["layout","validation","edges","type-mismatch"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}