{"record":{"id":"0e9eb2270f0b93dc","repo":"mermaid-js/mermaid","slug":"configuration-is-required-in-layout-data-0e9eb2","errorCode":null,"errorMessage":"Configuration is required in layout data","messagePattern":"Configuration 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":61,"sourceCode":"    };\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\n  return true;\n}\n","sourceCodeStart":43,"sourceCodeEnd":78,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts#L43-L78","documentation":"Second guard in validateLayoutData: `data` itself is truthy but `data.config` is missing. The cose-bilkent layout needs the MermaidConfig to drive cytoscape options, so a LayoutData without its config block is rejected before cytoscape is created. Thrown at layout.ts:61.","triggerScenarios":"A LayoutData object assembled without the config field, e.g. { rootNode, nodes, edges, layoutAlgorithm } with config omitted, or a partial spread that dropped config. Also if a transformer sets config to null explicitly.","commonSituations":"Custom diagram integrations that hand-build LayoutData and forget to attach the mermaid config; a refactor that moved config to a sibling property; or a mock/fixture used in tests missing the config block.","solutions":["Attach the active MermaidConfig to data.config before calling the layout (the standard render path does this automatically — use it instead of calling executeCoseBilkentLayout directly).","If building LayoutData manually, spread the config in: { ...rest, config: mermaidConfig }.","Add a unit-test fixture that includes a minimal valid config object.","Log data.config at the call site to confirm it is populated."],"exampleFix":"// before\n{ rootNode, nodes, edges, layoutAlgorithm: 'cose-bilkent' }\n// after\n{ rootNode, nodes, edges, layoutAlgorithm: 'cose-bilkent', config: mermaidConfig }","handlingStrategy":"validation","validationCode":"if (!data?.config) throw new Error('LayoutData.config missing — attach the active MermaidConfig');","typeGuard":"function hasConfig(d: any): d is { config: object } { return d && typeof d.config === 'object' && d.config !== null; }","tryCatchPattern":"try { validateLayoutData(data); } catch (e) { if (/Configuration is required/.test(String(e))) { data.config = mermaidConfig; validateLayoutData(data); } else throw e; }","preventionTips":["Use the standard render pipeline which attaches config automatically.","When building LayoutData manually, always spread the mermaid config.","Add a fixture/test that includes a valid config block."],"tags":["layout","cose-bilkent","validation","configuration"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}