{"record":{"id":"55f42f91d9b38ff3","repo":"mermaid-js/mermaid","slug":"an-align-directive-requires-at-least-two-members","errorCode":null,"errorMessage":"An align directive requires at least two members; got ${hint.members.length}","messagePattern":"An align directive requires at least two members; got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureDb.ts","lineNumber":265,"sourceCode":"      title,\n    };\n\n    this.edges.push(edge);\n    const lhsNode = this.nodes.get(lhsId);\n    const rhsNode = this.nodes.get(rhsId);\n    if (lhsNode && rhsNode) {\n      lhsNode.edges.push(this.edges[this.edges.length - 1]);\n      rhsNode.edges.push(this.edges[this.edges.length - 1]);\n    }\n  }\n\n  public getEdges(): ArchitectureEdge[] {\n    return this.edges;\n  }\n\n  public addLayoutHint(hint: ArchitectureLayoutHint): void {\n    if (hint.members.length < 2) {\n      throw new Error(\n        `An align directive requires at least two members; got ${hint.members.length}`\n      );\n    }\n    const seen = new Set<string>();\n    hint.members.forEach((id) => {\n      if (this.registeredIds.get(id) !== 'node') {\n        throw new Error(\n          `align ${hint.direction} references [${id}], which is not a service or junction`\n        );\n      }\n      if (seen.has(id)) {\n        throw new Error(`align ${hint.direction} lists [${id}] more than once`);\n      }\n      seen.add(id);\n    });\n    this.layoutHints.push(hint);\n  }\n","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L247-L283","documentation":"Thrown by ArchitectureDB.addLayoutHint when hint.members has fewer than 2 entries. An align directive aligns two or more nodes along a row or column, so a single-member or empty alignment is meaningless. Note the Langium grammar already requires `(members+=ID)+`, so this guard primarily protects non-grammar (programmatic) callers.","triggerScenarios":"Calling db.addLayoutHint({ direction: 'row', members: [] }) or members: ['only_one']. In DSL this is hard to hit because the grammar enforces >=1, but a single-member align can still slip through some code paths.","commonSituations":"Programmatic generation of layout hints that produces empty or singleton arrays; DSL edge cases where a rule reduces members to one; tests exercising the DB API directly.","solutions":["Ensure members contains at least 2 ids.","Skip emitting the hint entirely when fewer than 2 members would be present."],"exampleFix":"// before\ndb.addLayoutHint({ direction: 'row', members: ['a'] });\n// after\ndb.addLayoutHint({ direction: 'row', members: ['a', 'b'] });","handlingStrategy":"validation","validationCode":"function addLayoutHintSafe(db, hint) {\n  if (hint.members.length < 2) {\n    throw new Error(`align needs >=2 members; got ${hint.members.length}`);\n  }\n  db.addLayoutHint(hint);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Skip emitting align hints with fewer than 2 members.","When generating from data, filter out degenerate single-member alignments."],"tags":["architecture","layout","align","validation"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}