{"record":{"id":"1e48116b4d827c9d","repo":"mermaid-js/mermaid","slug":"edges-array-is-required-in-layout-data-1e4811","errorCode":null,"errorMessage":"Edges array is required in layout data","messagePattern":"Edges array is required in layout data","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts","lineNumber":73,"sourceCode":"export 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 (!data.rootNode) {\n    throw new Error('Root node is required');\n  }\n\n  if (!data.nodes || !Array.isArray(data.nodes)) {\n    throw new Error('No nodes found 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":55,"sourceCodeEnd":78,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts#L55-L78","documentation":"Fifth and final guard in validateLayoutData: `data.edges` is present but not an array (an undefined edges field also triggers it, since Array.isArray(undefined) is false). The cose-bilkent layout needs an edges array — possibly empty — to compute edge routes. Thrown at layout.ts:73. Unlike nodes, this check doesn't accept missing edges; they must be an array.","triggerScenarios":"A LayoutData with edges omitted entirely, or edges set to an object/Map/null. e.g. { config, rootNode, nodes, layoutAlgorithm } with no edges key. Array.isArray(null) is false, so explicitly-null edges also fail.","commonSituations":"A node-only diagram built manually without an edges field, a transform that stores edges under a different key (e.g. `connections`), or a fixture missing edges. Because the check requires an array, even 'no edges' must be expressed as [].","solutions":["Always set data.edges to an array (use [] when there are no edges).","Confirm the diagram-db layer emits edges as an array key named `edges`.","If your data model uses a different key, map it to edges before layout.","Add Array.isArray(data.edges) validation upstream to fail with a clearer message."],"exampleFix":"// before\n{ config, rootNode, nodes, layoutAlgorithm: 'cose-bilkent' } // edges missing\n// after\n{ config, rootNode, nodes, edges: [], layoutAlgorithm: 'cose-bilkent' }","handlingStrategy":"validation","validationCode":"if (!Array.isArray(data?.edges)) throw new Error('LayoutData.edges must be an array');","typeGuard":"function hasEdgesArray(d: any): d is { edges: unknown[] } { return Array.isArray(d?.edges); }","tryCatchPattern":"try { validateLayoutData(data); } catch (e) { if (/Edges array is required/.test(String(e))) { data.edges = []; validateLayoutData(data); } else throw e; }","preventionTips":["Always set edges to [] when there are none — never omit or null it.","Ensure the transform uses the `edges` key name.","Validate with Array.isArray upstream."],"tags":["layout","cose-bilkent","validation","graph"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}