{"record":{"id":"e8bda844f3f3ffb7","repo":"mermaid-js/mermaid","slug":"invalid-direction-given-for-right-hand-side-of-edg","errorCode":null,"errorMessage":"Invalid direction given for right hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(rhsDir)}","messagePattern":"Invalid direction given for right 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":209,"sourceCode":"  }\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      );\n    }\n\n    const lhsGroupId = this.nodes.get(lhsId)!.in;\n    const rhsGroupId = this.nodes.get(rhsId)!.in;\n    if (lhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) {","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/architecture/architectureDb.ts#L191-L227","documentation":"Thrown by ArchitectureDB.addEdge when rhsDir fails the isArchitectureDirection type guard. Identical contract to the LHS check: rhsDir must be one of 'L', 'R', 'T', 'B'. This check runs only after lhsDir has already passed, so reaching it means the LHS direction was valid.","triggerScenarios":"Calling db.addEdge({ lhsId, rhsId, lhsDir: 'L', rhsDir: 'down' }) or rhsDir: undefined or any value outside {L,R,T,B}.","commonSituations":"Same as the LHS case — lowercase or word-form directions, undefined from incomplete objects, external token mismatch.","solutions":["Set rhsDir to one of 'L', 'R', 'T', 'B'.","Pre-validate both directions with isArchitectureDirection before constructing the edge object."],"exampleFix":"// before\ndb.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'L', rhsDir: 'down' });\n// after\ndb.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'L', rhsDir: 'B' });","handlingStrategy":"type-guard","validationCode":"import { isArchitectureDirection } from './architectureTypes.js';\nfunction addEdgeSafe(db, e) {\n  if (!isArchitectureDirection(e.rhsDir)) {\n    throw new Error(`rhsDir must be one of L,R,T,B; got ${String(e.rhsDir)}`);\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":["Validate both lhsDir and rhsDir with isArchitectureDirection before addEdge.","Centralize direction constants to avoid typos."],"tags":["architecture","edge","validation","direction"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}