n8n-io/n8n · error · Error

Failed to parse at

Error message

Failed to parse ${label} at ${path}: ${msg}

What it means

The readJson helper (line 247) reads a file and calls JSON.parse on its contents. When parsing fails, the original SyntaxError message is wrapped with the file path and a human label (e.g. 'test case', 'existing manifest') so the developer knows exactly which file is malformed and why. This is called from multiple sites: test-case loading (line 504), tier-dataset reading (line 423), and existing-manifest reading (line 345).

Solutions

  1. Open the file at the path shown in the error and fix the JSON syntax error described in the message
  2. If it is a truncated manifest from a crashed run, delete it and re-run (or use --manifest with a fresh path)
  3. Restore a corrupt test case from git: git checkout -- <path>
  4. Validate the file with a JSON linter: npx prettier --check <path> or jq . <path>
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate JSON files before the CLI reads them:
import { readFileSync } from 'fs';
function assertValidJson(path: string): void {
  try {
    JSON.parse(readFileSync(path, 'utf-8'));
  } catch (e) {
    throw new Error(`Pre-check failed: ${path} is not valid JSON: ${(e as Error).message}`);
  }
}

Try / catch

try {
  const data = JSON.parse(content);
} catch (error) {
  const msg = error instanceof Error ? error.message : String(error);
  throw new Error(`Failed to parse ${label} at ${path}: ${msg}`);
}

Prevention

When it happens

Trigger: A test case JSON file (data/workflows/*.json), the manifest file, or any JSON read by the CLI contains invalid JSON syntax — trailing comma, unquoted keys, truncated content from a partial write, BOM character, or corrupted encoding.

Common situations: A previous build run crashed mid-write leaving a truncated JSON file. A hand-edited test case has a syntax error. A merge conflict left conflict markers inside a JSON file. An encoding issue introduced a BOM or control characters.

Understand the failure class

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/b44e31a24fc2153d. Report an issue: GitHub.

Appendix: source

Thrown at packages/@n8n/instance-ai/evaluations/cli/build-mcp-manifest.ts:253

	}

	mkdirSync(result.outputDir, { recursive: true });
	if (!result.manifestPath) result.manifestPath = join(result.outputDir, 'manifest.json');
	if (!result.logDir) result.logDir = join(result.outputDir, 'logs');
	const base = result.manifestPath.replace(/\.json$/, '');
	result.statsPath = `${base}-stats.json`;
	mkdirSync(result.logDir, { recursive: true });

	return { helpRequested: false, args: result };
}

function readJson(path: string, label: string): unknown {
	const content = readFileSync(path, 'utf-8');
	try {
		return JSON.parse(content);
	} catch (error) {
		const msg = error instanceof Error ? error.message : String(error);
		throw new Error(`Failed to parse ${label} at ${path}: ${msg}`);
	}
}

function nextArg(argv: string[], i: number, flag: string): string {
	const value = argv[i + 1];
	if (value === undefined || value.startsWith('--')) {
		throw new Error(`Missing value for ${flag}`);
	}
	return value;
}

function parseIntArg(argv: string[], i: number, flag: string): number {
	const raw = nextArg(argv, i, flag);
	const parsed = parseInt(raw, 10);
	if (Number.isNaN(parsed)) throw new Error(`Invalid integer for ${flag}`);
	return parsed;
}

View on GitHub (pinned to 5ac6606e81)