{"record":{"id":"b0a33fe6ffc9ede9","repo":"mermaid-js/mermaid","slug":"layout-data-is-required","errorCode":null,"errorMessage":"Layout data is required","messagePattern":"Layout data is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid-layout-tidy-tree/src/layout.ts","lineNumber":637,"sourceCode":"      points,\n      sourceSection: sourceNode?.section,\n      targetSection: targetNode?.section,\n      sourceWidth: sourceNode?.width,\n      sourceHeight: sourceNode?.height,\n      targetWidth: targetNode?.width,\n      targetHeight: targetNode?.height,\n    };\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 (!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":619,"sourceCodeEnd":654,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid-layout-tidy-tree/src/layout.ts#L619-L654","documentation":"Thrown by validateLayoutData when the data argument is falsy (null/undefined). This is the first check in the public validator; it exists so callers can pre-flight a LayoutData object before paying for the layout pass. It is a synchronous throw, not a promise rejection.","triggerScenarios":"Calling validateLayoutData(null), validateLayoutData(undefined), or passing a variable that was never assigned a LayoutData object.","commonSituations":"A parser returned null/undefined for a diagram that failed to produce layout data, an async fetch of graph data resolved to nothing, or an uninitialized field on an object was forwarded straight into the validator.","solutions":["Initialize LayoutData with empty arrays and a config object rather than leaving it null.","Add a null check at the call site and skip validation/layout when data is absent.","Trace the producer of the data argument and ensure it always returns an object."],"exampleFix":"// before\nvalidateLayoutData(maybeData);\n\n// after\nif (!maybeData) {\n  throw new TypeError('LayoutData producer returned nothing');\n}\nvalidateLayoutData(maybeData);","handlingStrategy":"type-guard","validationCode":"if (data == null) {\n  throw new TypeError('LayoutData is required');\n}\nvalidateLayoutData(data);","typeGuard":"function isLayoutData(data: unknown): data is object {\n  return data != null && typeof data === 'object';\n}","tryCatchPattern":null,"preventionTips":["Type the parameter as LayoutData (non-nullable) at every producer.","Default LayoutData to an object literal at construction: { nodes: [], edges: [], config: {} }."],"tags":["layout","validation","null-check"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}