{"record":{"id":"4800d0bd24b678b5","repo":"n8n-io/n8n","slug":"existing-manifest-at-manifestpath-is-malformed","errorCode":null,"errorMessage":"Existing manifest at ${manifestPath} is malformed; remove or fix it before re-running:\\n  ${msg}","messagePattern":"Existing manifest at (.+?) is malformed; remove or fix it before re-running:\\\\n  (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/evaluations/cli/build-mcp-manifest.ts","lineNumber":348,"sourceCode":"\t\tdurationMs: result.durationMs,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Manifest + stats output\n// ---------------------------------------------------------------------------\n\nfunction readExistingWorkflows(manifestPath: string): Record<string, string[]> {\n\tif (!existsSync(manifestPath)) return {};\n\t// The file exists — it must be parseable. Silently treating a malformed\n\t// manifest as empty would clobber accumulated entries on the next write\n\t// (especially destructive with --append, where the entire prior corpus\n\t// could be lost). Force the user to fix or remove the file first.\n\ttry {\n\t\treturn { ...prebuiltManifestSchema.parse(readJson(manifestPath, 'existing manifest')) };\n\t} catch (error) {\n\t\tconst msg = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(\n\t\t\t`Existing manifest at ${manifestPath} is malformed; remove or fix it before re-running:\\n  ${msg}`,\n\t\t);\n\t}\n}\n\nfunction writeManifest(args: CliArgs, results: BuildOutcome[]): void {\n\tconst workflows = readExistingWorkflows(args.manifestPath);\n\n\tif (!args.append) {\n\t\t// Without --append, clear entries for slugs we just rebuilt; preserve\n\t\t// other slugs in the existing manifest.\n\t\tfor (const slug of new Set(results.map((r) => r.slug))) {\n\t\t\tdelete workflows[slug];\n\t\t}\n\t}\n\n\tfor (const r of results) {\n\t\tif (!r.workflowId) continue;","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/evaluations/cli/build-mcp-manifest.ts#L330-L366","documentation":"The readExistingWorkflows function (line 338) reads a previously-written manifest to merge or update it. It parses the file through the prebuiltManifestSchema Zod schema to ensure the structure matches what the eval loader expects. If JSON parsing or Zod validation fails, the error is thrown rather than silently treating the file as empty — silently empty would clobber accumulated workflow entries on the next write, which is especially destructive with --append where the entire prior corpus could be lost.","triggerScenarios":"The manifest file at --manifest (default <output-dir>/manifest.json) exists but is either not valid JSON or does not match the prebuiltManifestSchema shape (an object mapping slug to an array of workflow-id strings). This occurs when the file was hand-edited, partially written by a crashed run, or is from an incompatible older schema version.","commonSituations":"A previous build run crashed mid-write leaving a truncated manifest. The manifest was manually edited and broken. A schema change in prebuiltManifestSchema made an older manifest invalid. A git merge left conflict markers in the file.","solutions":["Delete the malformed manifest and re-run: rm <manifest-path>","Fix the JSON syntax or schema shape — the error message includes the underlying parse/schema detail","Use --manifest to write to a different path, preserving the old file","Restore from git if committed: git checkout -- <manifest-path>"],"exampleFix":"# before: manifest.json is truncated/corrupt from a crashed run\n# after\nrm manifest.json && pnpm eval:build-mcp-manifest","handlingStrategy":"validation","validationCode":"// Pre-validate an existing manifest against the Zod schema before running:\nimport { readFileSync } from 'fs';\nimport { prebuiltManifestSchema } from '../harness/prebuilt-workflows';\ntry {\n  prebuiltManifestSchema.parse(JSON.parse(readFileSync(manifestPath, 'utf-8')));\n} catch (e) {\n  console.error(`Manifest is malformed, removing: ${manifestPath}`);\n  // rmSync(manifestPath);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return prebuiltManifestSchema.parse(readJson(manifestPath, 'existing manifest'));\n} catch (error) {\n  const msg = error instanceof Error ? error.message : String(error);\n  throw new Error(`Existing manifest at ${manifestPath} is malformed; remove or fix it: ${msg}`);\n}","preventionTips":["Never hand-edit the manifest JSON without validating it afterward","Use atomic writes in build scripts so a crash never leaves a truncated manifest","Back up or commit the manifest before re-running with --append"],"tags":["json","validation","manifest","filesystem","data-integrity","build-mcp-manifest"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}