{"record":{"id":"5e8008db2283feb8","repo":"mermaid-js/mermaid","slug":"layout-data-is-required-5e8008","errorCode":null,"errorMessage":"Layout data is required","messagePattern":"Layout data is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts","lineNumber":57,"sourceCode":"\n    return {\n      nodes: positionedNodes,\n      edges: positionedEdges,\n    };\n  } catch (error) {\n    log.error('Error in cose-bilkent layout algorithm:', error);\n    throw error;\n  }\n}\n\n/**\n * 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 (!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","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts#L39-L75","documentation":"First guard in validateLayoutData, thrown when executeCoseBilkentLayout receives a falsy `data` argument (null/undefined). validateLayoutData runs at the top of the cose-bilkent layout (layout.ts:29) before any cytoscape work, so this indicates the caller passed no layout payload at all. Subsequent guards (108–111) check inner fields; this one catches total absence.","triggerScenarios":"Calling executeCoseBilkentLayout(undefined, config) or render of a LayoutData built from a diagram that produced no parse result (e.g. an empty/malformed graph that yielded null before reaching layout). Any path where the LayoutData object is null/undefined reaches this throw.","commonSituations":"A diagram type whose parser returned null/undefined being routed to the cose-bilkent layout, an integration that constructs LayoutData conditionally and skips the assignment, or a refactor that dropped the data argument. Mostly an internal-contract violation rather than an end-user config error.","solutions":["Ensure the LayoutData passed to executeCoseBilkentLayout / render is a fully constructed object, not null/undefined.","Inspect the upstream parser/diagram-db step that builds LayoutData — if it returned null, fix or short-circuit before layout.","Add a guard at the call site: if (!data) return; to skip layout for empty diagrams.","Reproduce with logging just before the layout call to see why data is falsy."],"exampleFix":"// before\nawait executeCoseBilkentLayout(maybeData, config); // maybeData may be undefined\n// after\nif (!maybeData) throw new Error('parser produced no layout data');\nawait executeCoseBilkentLayout(maybeData, config);","handlingStrategy":"validation","validationCode":"function hasLayoutData(data: unknown): data is object {\n  return data !== null && data !== undefined;\n}\nif (!hasLayoutData(data)) throw new Error('no layout data produced upstream');","typeGuard":"function isLayoutData(x: unknown): x is { config: unknown; rootNode: unknown; nodes: unknown[]; edges: unknown[] } {\n  return !!x && typeof x === 'object' && 'config' in x && 'rootNode' in x && Array.isArray((x as any).nodes) && Array.isArray((x as any).edges);\n}","tryCatchPattern":"try { validateLayoutData(data); } catch (e) { if (/Layout data is required/.test(String(e))) return; throw e; }","preventionTips":["Always construct a LayoutData object before layout; never pass optional/null.","Short-circuit rendering for diagrams that produced no parse result.","Add an upstream assert that parse returned a value."],"tags":["layout","cose-bilkent","validation","internal"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}