{"record":{"id":"ccc5a5d509680ad5","repo":"mermaid-js/mermaid","slug":"invalid-direction-given-for-left-hand-side-of-edge","errorCode":null,"errorMessage":"Invalid direction given for left hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(lhsDir)}","messagePattern":"Invalid direction given for left hand side of edge (.+?)--(.+?)\\. Expected \\(L,R,T,B\\) got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/architecture/architectureDb.ts","lineNumber":204,"sourceCode":"      in: parent,\n    });\n  }\n  public getGroups(): ArchitectureGroup[] {\n    return [...this.groups.values()];\n  }\n  public addEdge({\n    lhsId,\n    rhsId,\n    lhsDir,\n    rhsDir,\n    lhsInto,\n    rhsInto,\n    lhsGroup,\n    rhsGroup,\n    title,\n  }: ArchitectureEdge): void {\n    if (!isArchitectureDirection(lhsDir)) {\n      throw new Error(\n        `Invalid direction given for left hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(lhsDir)}`\n      );\n    }\n    if (!isArchitectureDirection(rhsDir)) {\n      throw new Error(\n        `Invalid direction given for right hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(rhsDir)}`\n      );\n    }\n\n    if (!this.nodes.has(lhsId) && !this.groups.has(lhsId)) {\n      throw new Error(\n        `The left-hand id [${lhsId}] does not yet exist. Please create the service/group before declaring an edge to it.`\n      );\n    }\n    if (!this.nodes.has(rhsId) && !this.groups.has(rhsId)) {\n      throw new Error(\n        `The right-hand id [${rhsId}] does not yet exist. Please create the service/group before declaring an edge to it.`\n      );","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L186-L222","documentation":"Thrown by ArchitectureDB.addEdge when lhsDir fails the isArchitectureDirection type guard. Valid directions are exactly the single uppercase characters 'L', 'R', 'T', 'B' (left, right, top, bottom). Any other value — lowercase, multi-character, undefined, or a number — is rejected before the edge is created.","triggerScenarios":"Calling db.addEdge({ lhsId, rhsId, lhsDir: 'left', rhsDir: 'R' }) or lhsDir: 'x', or lhsDir: undefined. The first direction check that fails is always the LHS one.","commonSituations":"Programmatic API misuse passing full words or lowercase; spreads/merges that leave lhsDir undefined; DSL grammar changes that emit a new token not understood by older code.","solutions":["Use one of the four uppercase chars: 'L', 'R', 'T', 'B' for lhsDir.","If directions come from external input, validate with isArchitectureDirection before calling addEdge."],"exampleFix":"// before\ndb.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'left', rhsDir: 'R' });\n// after\ndb.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'L', rhsDir: 'R' });","handlingStrategy":"type-guard","validationCode":"import { isArchitectureDirection } from './architectureTypes.js';\nfunction addEdgeSafe(db, e) {\n  if (!isArchitectureDirection(e.lhsDir)) {\n    throw new Error(`lhsDir must be one of L,R,T,B; got ${String(e.lhsDir)}`);\n  }\n  db.addEdge(e);\n}","typeGuard":"import { isArchitectureDirection } from './architectureTypes.js';\nconst isValidDirection = (d: unknown): d is 'L'|'R'|'T'|'B' =>\n  d === 'L' || d === 'R' || d === 'T' || d === 'B';","tryCatchPattern":null,"preventionTips":["Always use uppercase single-char direction constants.","Run isArchitectureDirection on both directions before constructing an edge."],"tags":["architecture","edge","validation","direction"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}