mermaid-js/mermaid · error

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

Error message

Invalid direction given for left hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(lhsDir)}

What it means

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.

Source

Thrown at packages/mermaid/src/diagrams/architecture/architectureDb.ts:204

      in: parent,
    });
  }
  public getGroups(): ArchitectureGroup[] {
    return [...this.groups.values()];
  }
  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.`
      );

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Use one of the four uppercase chars: 'L', 'R', 'T', 'B' for lhsDir.
  2. If directions come from external input, validate with isArchitectureDirection before calling addEdge.

Example fix

// before
db.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'left', rhsDir: 'R' });
// after
db.addEdge({ lhsId: 'a', rhsId: 'b', lhsDir: 'L', rhsDir: 'R' });
Defensive patterns

Strategy: type-guard

Validate before calling

import { isArchitectureDirection } from './architectureTypes.js';
function addEdgeSafe(db, e) {
  if (!isArchitectureDirection(e.lhsDir)) {
    throw new Error(`lhsDir must be one of L,R,T,B; got ${String(e.lhsDir)}`);
  }
  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: 'left', rhsDir: 'R' }) or lhsDir: 'x', or lhsDir: undefined. The first direction check that fails is always the LHS one.

Common situations: 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.

Related errors


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