{"record":{"id":"f9724daba016dfee","repo":"mermaid-js/mermaid","slug":"architecture-layout-failed-a-declared-align-row","errorCode":null,"errorMessage":"Architecture layout failed: a declared `align row|column` directive likely contradicts the edge directions, or two declared alignments overlap on a shared node. Check that the order of members in each `align` chain is consistent with the edges between them, and that no node appears in two `align` directives along the same axis.","messagePattern":"Architecture layout failed: a declared `align row\\|column` directive likely contradicts the edge directions, or two declared alignments overlap on a shared node\\. Check that the order of members in each `align` chain is consistent with the edges between them, and that no node appears in two `align` directives along the same axis\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureRenderer.ts","lineNumber":592,"sourceCode":"            edge.style('segment-distances', distances);\n            edge.style('segment-weights', weights);\n          }\n        }\n      }\n      cy.endBatch();\n      withSeededRandom(seed, () => layout.run());\n    });\n    try {\n      withSeededRandom(seed, () => layout.run());\n    } catch (err) {\n      // fcose throws a raw `RangeError: Invalid array length` from inside\n      // FDLayout.calcGrid when the constraints it receives are unsatisfiable\n      // (e.g. an `align row|column` chain whose member order contradicts the\n      // edge directions, or two declared alignments that overlap on a node).\n      // Rethrow with actionable context so users don't have to chase the\n      // failure into fcose internals.\n      if (err instanceof RangeError && err.message.includes('Invalid array length')) {\n        throw new Error(\n          'Architecture layout failed: a declared `align row|column` directive ' +\n            'likely contradicts the edge directions, or two declared alignments ' +\n            'overlap on a shared node. Check that the order of members in each ' +\n            '`align` chain is consistent with the edges between them, and that ' +\n            'no node appears in two `align` directives along the same axis.'\n        );\n      }\n      throw err;\n    }\n\n    cy.ready((e) => {\n      log.info('Ready', e);\n      resolve(cy);\n    });\n  });\n}\n\nexport const draw: DrawDefinition = async (text, id, _version, diagObj: Diagram) => {","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureRenderer.ts#L574-L610","documentation":"Thrown by the architecture renderer when the fcose layout engine raises a RangeError with the message 'Invalid array length' during layout.run(). fcose raises this from FDLayout.calcGrid when the alignment constraints it receives are unsatisfiable. The renderer catches the raw RangeError and rethrows with actionable context. This is a render-time error, not a parse-time one — the DB accepted the diagram, but the layout math has no solution.","triggerScenarios":"An `align row` or `align column` chain whose member order contradicts the directions implied by edges between those members (e.g. align says A is left of B but an edge forces A right of B). Also: the same node appearing in two align directives along the same axis, which over-constrains the system.","commonSituations":"Complex diagrams mixing many edges with several align directives; iterative editing where an align directive is added without re-checking edge directions; align chains copied from another diagram whose edges run the opposite way.","solutions":["Reorder each align chain's members so the order is consistent with the edge directions between them.","Ensure no node appears in two `align` directives on the same axis (two rows or two columns).","Temporarily remove align directives one at a time to isolate which constraint contradicts the edges.","If the conflict is unintended, flip the direction of the offending edge(s) to match the desired alignment."],"exampleFix":"// before — edge says b is right of a, but align says a is right of b\narchitecture-beta\n  service a\n  service b\n  a:R -- b:L\n  align row: b, a\n// after — make the align order match the edge-implied order\narchitecture-beta\n  service a\n  service b\n  a:R -- b:L\n  align row: a, b","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await mermaid.render(id, diagramText);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Architecture layout failed')) {\n    // Strip or reorder conflicting `align` directives, then retry.\n    console.warn('Layout constraint conflict:', err.message);\n  }\n  throw err;\n}","preventionTips":["Keep align member order consistent with the edge-implied spatial order.","Never list the same node in two align directives on the same axis.","When adding a new align directive, mentally verify it does not contradict existing edges."],"tags":["architecture","layout","fcose","constraint-conflict","render-time"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}