mermaid-js/mermaid · error

Invalid direction given for right hand side of edge ${lhsId}

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.

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)

Solutions

  1. Set rhsDir to one of 'L', 'R', 'T', 'B'.
  2. 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

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


AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12). Data as JSON: /api/errors/e8bda844f3f3ffb7. Report an issue: GitHub.