mermaid-js/mermaid · error
Invalid direction given for right hand side of edge
Error message
Invalid direction given for right hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(rhsDir)} What it means
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.
Solutions
- Set rhsDir to one of 'L', 'R', 'T', 'B'.
- Pre-validate both directions with isArchitectureDirection before constructing the edge object.
Example fix
// before
db.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'L', rhsDir: 'down' });
// after
db.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'L', rhsDir: 'B' }); Defensive patterns
Strategy: type-guard
Validate before calling
import { isArchitectureDirection } from './architectureTypes.js';
function addEdgeSafe(db, e) {
if (!isArchitectureDirection(e.rhsDir)) {
throw new Error(`rhsDir must be one of L,R,T,B; got ${String(e.rhsDir)}`);
}
db.addEdge(e);
} Type guard
import { isArchitectureDirection } from './architectureTypes.js';
const isValidDirection = (d: unknown): d is 'L'|'R'|'T'|'B' =>
d === 'L' || d === 'R' || d === 'T' || d === 'B'; Prevention
- Validate both lhsDir and rhsDir with isArchitectureDirection before addEdge.
- Centralize direction constants to avoid typos.
When it happens
Trigger: Calling db.addEdge({ lhsId, rhsId, lhsDir: 'L', rhsDir: 'down' }) or rhsDir: undefined or any value outside {L,R,T,B}.
Common situations: Same as the LHS case — lowercase or word-form directions, undefined from incomplete objects, external token mismatch.
Related errors
- Invalid direction given for left hand side of edge
- The left-hand id [ ] is modified to traverse the group…
- The right-hand id [ ] is modified to traverse the group…
- An align directive requires at least two members; got
- The group [ ] cannot be placed within itself
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/e8bda844f3f3ffb7.
Report an issue: GitHub.
Appendix: source
Thrown at packages/mermaid/src/diagrams/architecture/architectureDb.ts:209
}
public addEdge({
lhsId,
rhsId,
lhsDir,
rhsDir,
lhsInto,
rhsInto,
lhsGroup,
rhsGroup,
title,
}: ArchitectureEdge): void {
if (!isArchitectureDirection(lhsDir)) {
throw new Error(
`Invalid direction given for left hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(lhsDir)}`
);
}
if (!isArchitectureDirection(rhsDir)) {
throw new Error(
`Invalid direction given for right hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(rhsDir)}`
);
}
if (!this.nodes.has(lhsId) && !this.groups.has(lhsId)) {
throw new Error(
`The left-hand id [${lhsId}] does not yet exist. Please create the service/group before declaring an edge to it.`
);
}
if (!this.nodes.has(rhsId) && !this.groups.has(rhsId)) {
throw new Error(
`The right-hand id [${rhsId}] does not yet exist. Please create the service/group before declaring an edge to it.`
);
}
const lhsGroupId = this.nodes.get(lhsId)!.in;
const rhsGroupId = this.nodes.get(rhsId)!.in;
if (lhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) {View on GitHub (pinned to d93e9c88c0)