{"record":{"id":"5424c079f6042169","repo":"Egonex-AI/Understand-Anything","slug":"invalid-knowledge-graph-result-fatal-unknow","errorCode":null,"errorMessage":"Invalid knowledge graph: ${result.fatal ?? \"unknown error\"}","messagePattern":"Invalid knowledge graph: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"understand-anything-plugin/packages/core/src/persistence/index.ts","lineNumber":112,"sourceCode":"    join(dir, GRAPH_FILE),\n    JSON.stringify(sanitised, null, 2),\n    \"utf-8\",\n  );\n}\n\nexport function loadGraph(\n  projectRoot: string,\n  options?: { validate?: boolean },\n): KnowledgeGraph | null {\n  const filePath = join(resolveUaDir(projectRoot), GRAPH_FILE);\n  if (!existsSync(filePath)) return null;\n\n  const data = JSON.parse(readFileSync(filePath, \"utf-8\"));\n\n  if (options?.validate !== false) {\n    const result = validateGraph(data);\n    if (!result.success) {\n      throw new Error(\n        `Invalid knowledge graph: ${result.fatal ?? \"unknown error\"}`,\n      );\n    }\n    return result.data as KnowledgeGraph;\n  }\n\n  return data as KnowledgeGraph;\n}\n\nexport function saveMeta(projectRoot: string, meta: AnalysisMeta): void {\n  const dir = ensureDir(projectRoot);\n  writeFileSync(join(dir, META_FILE), JSON.stringify(meta, null, 2), \"utf-8\");\n}\n\nexport function loadMeta(projectRoot: string): AnalysisMeta | null {\n  const filePath = join(resolveUaDir(projectRoot), META_FILE);\n  if (!existsSync(filePath)) return null;\n  return JSON.parse(readFileSync(filePath, \"utf-8\")) as AnalysisMeta;","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/understand-anything-plugin/packages/core/src/persistence/index.ts#L94-L130","documentation":"Thrown by loadGraph when the on-disk knowledge-graph.json fails schema validation. The function reads .ua/knowledge-graph.json (or the legacy .understand-anything/ variant), parses it, and runs validateGraph; on failure the fatal reason from the validator is interpolated. Validation can be skipped by passing { validate: false }.","triggerScenarios":"knowledge-graph.json is corrupt or hand-edited; an older graph format written by a prior tool version; validateGraph reports a fatal issue such as 'Invalid input: not an object', 'Missing or invalid project metadata', or 'No valid nodes found in knowledge graph'; a partial write left truncated JSON.","commonSituations":"Downgrading the tool after a newer graph format was produced; a crashed/killed analysis leaving a half-written file; merging graphs across forks; manual edits to knowledge-graph.json that drop required fields.","solutions":["Re-run the analysis (/understand) to regenerate a schema-conformant knowledge-graph.json.","Call loadGraph(projectRoot, { validate: false }) to read the raw data if you will re-validate or migrate it yourself.","Inspect the fatal message and the full validateGraph issues list to identify which node/project field is wrong, then repair that entry.","Restore knowledge-graph.json from version control or a backup if it was corrupted."],"exampleFix":"// before\nconst g = loadGraph(projectRoot);\n// after — skip validation for a self-managed read, or regenerate\nconst g = loadGraph(projectRoot, { validate: false });","handlingStrategy":"validation","validationCode":"import { validateGraph } from '@understand-anything/core/schema';\nimport { readFileSync } from 'node:fs';\nconst raw = JSON.parse(readFileSync(graphPath, 'utf-8'));\nconst result = validateGraph(raw);\nif (!result.success) { /* handle before calling loadGraph */ }","typeGuard":"import { validateGraph } from '@understand-anything/core/schema';\nfunction isValidGraph(data: unknown): data is KnowledgeGraph {\n  return validateGraph(data).success;\n}","tryCatchPattern":"try { const g = loadGraph(projectRoot); } catch (e) { if (/Invalid knowledge graph/.test(String((e as Error).message))) { /* regenerate or load with validate:false */ } throw e; }","preventionTips":["Treat knowledge-graph.json as build output — regenerate rather than hand-edit.","Skip validation with { validate: false } only when you will re-validate or migrate yourself.","Keep the tool version consistent with the graph format on disk."],"tags":["persistence","schema","validation","json"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}