mermaid-js/mermaid · error · Error

Closest parent position not found for commit ${commit.id}

Error message

Closest parent position not found for commit ${commit.id}

What it means

Error "Closest parent position not found for commit ${commit.id}" thrown in mermaid-js/mermaid.

Source

Thrown at packages/mermaid/src/diagrams/git/gitGraphRenderer.ts:192

      if (curPos <= maxPosition) {
        maxPosition = curPos;
      }
      const x = branchPos.get(commit.branch)!.pos;
      const y = curPos - LAYOUT_OFFSET;
      commitPos.set(commit.id, { x: x, y: y });
    }
  });
};

const findClosestParentPos = (commit: Commit): number => {
  const closestParent = findClosestParent(commit.parents.filter((p) => p !== null));
  if (!closestParent) {
    throw new Error(`Closest parent not found for commit ${commit.id}`);
  }

  const closestParentPos = commitPos.get(closestParent)?.y;
  if (closestParentPos === undefined) {
    throw new Error(`Closest parent position not found for commit ${commit.id}`);
  }
  return closestParentPos;
};

const calculateCommitPosition = (commit: Commit): number => {
  const closestParentPos = findClosestParentPos(commit);
  return closestParentPos + COMMIT_STEP;
};

const setCommitPosition = (commit: Commit, curPos: number): CommitPosition => {
  const branch = branchPos.get(commit.branch);

  if (!branch) {
    throw new Error(`Branch not found for commit ${commit.id}`);
  }

  const x = branch.pos;
  const y = curPos + LAYOUT_OFFSET;

View on GitHub (pinned to d93e9c88c0)

When it happens

Trigger: Thrown at packages/mermaid/src/diagrams/git/gitGraphRenderer.ts:192 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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