Egonex-AI/Understand-Anything · error · Error

Invalid domain graph: ${result.fatal ?? "unknown error"}

Error message

Invalid domain graph: ${result.fatal ?? "unknown error"}

What it means

Thrown by loadDomainGraph, the domain-graph counterpart to loadGraph. It reads .ua/domain-graph.json, parses it, and validates with the same validateGraph; any fatal validation failure is surfaced with the validator's fatal message. Like loadGraph it accepts { validate: false } to bypass.

Source

Thrown at understand-anything-plugin/packages/core/src/persistence/index.ts:189

    join(dir, DOMAIN_GRAPH_FILE),
    JSON.stringify(sanitised, null, 2),
    "utf-8",
  );
}

export function loadDomainGraph(
  projectRoot: string,
  options?: { validate?: boolean },
): KnowledgeGraph | null {
  const filePath = join(resolveUaDir(projectRoot), DOMAIN_GRAPH_FILE);
  if (!existsSync(filePath)) return null;

  const data = JSON.parse(readFileSync(filePath, "utf-8"));

  if (options?.validate !== false) {
    const result = validateGraph(data);
    if (!result.success) {
      throw new Error(
        `Invalid domain graph: ${result.fatal ?? "unknown error"}`,
      );
    }
    return result.data as KnowledgeGraph;
  }

  return data as KnowledgeGraph;
}

View on GitHub (pinned to 32944829e7)

Solutions

  1. Regenerate the domain graph via the domain analysis pipeline.
  2. Read with loadDomainGraph(projectRoot, { validate: false }) when you intend to migrate or self-validate the structure.
  3. Inspect the fatal message from validateGraph to pinpoint the offending field and repair it.
  4. Restore domain-graph.json from a backup or version control.

Example fix

// before
const dg = loadDomainGraph(projectRoot);
// after
const dg = loadDomainGraph(projectRoot, { validate: false });
Defensive patterns

Strategy: validation

Validate before calling

import { validateGraph } from '@understand-anything/core/schema';
const raw = JSON.parse(readFileSync(domainGraphPath, 'utf-8'));
if (!validateGraph(raw).success) { /* handle before calling loadDomainGraph */ }

Type guard

import { validateGraph } from '@understand-anything/core/schema';
function isValidDomainGraph(data: unknown): data is KnowledgeGraph {
  return validateGraph(data).success;
}

Try / catch

try { const dg = loadDomainGraph(projectRoot); } catch (e) { if (/Invalid domain graph/.test(String((e as Error).message))) { /* regenerate or load with validate:false */ } throw e; }

Prevention

When it happens

Trigger: domain-graph.json is missing required fields, has no valid nodes, lacks project metadata, or is structurally malformed (not an object, truncated JSON, schema-drift from an older version). Distinct from error 3 only in which file is loaded.

Common situations: A domain graph produced by a different/older tool version; a partial write after an interrupted domain analysis; manual editing of domain-graph.json; a graph assembled by a custom pipeline that did not match the schema.

Related errors


AI-assisted analysis of Egonex-AI/Understand-Anything@32944829e7 (2026-08-12). Data as JSON: /api/errors/09d790f1ceac342f. Report an issue: GitHub.