{"record":{"id":"753aaa1ad7eda90e","repo":"n8n-io/n8n","slug":"failed-to-parse-discovery-test-case-filepath","errorCode":null,"errorMessage":"Failed to parse discovery test case ${filePath}: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to parse discovery test case (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/evaluations/data/discovery/index.ts","lineNumber":70,"sourceCode":"\t\t\t}),\n\t\trationale: z.string().optional(),\n\t\tmaxSteps: z.number().int().positive().optional(),\n\t})\n\t.strict();\n\nexport interface DiscoveryTestCaseWithFile {\n\ttestCase: DiscoveryTestCase;\n\t/** Filename without extension, e.g. \"slack-oauth-credential-setup\" */\n\tfileSlug: string;\n}\n\nfunction parseTestCaseFile(filePath: string): DiscoveryTestCase {\n\tconst content = readFileSync(filePath, 'utf-8');\n\tlet raw: unknown;\n\ttry {\n\t\traw = JSON.parse(content);\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to parse discovery test case ${filePath}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tconst parsed = discoveryTestCaseSchema.safeParse(raw);\n\tif (!parsed.success) {\n\t\tconst issues = parsed.error.issues\n\t\t\t.map((issue) => `${issue.path.join('.') || '(root)'}: ${issue.message}`)\n\t\t\t.join('; ');\n\t\tthrow new Error(`Invalid discovery test case ${filePath}: ${issues}`);\n\t}\n\treturn parsed.data;\n}\n\nfunction parseSubstringList(value: string | undefined): string[] {\n\tif (!value) return [];\n\treturn value\n\t\t.split(',')\n\t\t.map((s) => s.trim().toLowerCase())","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/evaluations/data/discovery/index.ts#L52-L88","documentation":"Thrown by `parseTestCaseFile()` in data/discovery/index.ts when `JSON.parse()` throws on a discovery test-case file. This is a pure syntax/lexing failure — unmatched braces, trailing commas (forbidden in strict JSON), single-quoted strings, control characters, or a truncated file. The original parse error is appended so the developer sees the JSON-level cause (line/column). Once parsing succeeds, the file is handed to `discoveryTestCaseSchema.safeParse`, which is a different failure path (error 430).","triggerScenarios":"Hand-edited discovery case file with a trailing comma or comment. A file truncated by a crashed editor or a bad git merge. A file saved as JSONC or JSON5 (this loader uses strict `JSON.parse`). A BOM or CRLF issue on Windows-edited files in rare cases. A copy-paste that introduced smart quotes.","commonSituations":"Authoring a new discovery case and forgetting JSON's strictness (no comments, no trailing commas). A merge conflict marker left in the file. An editor that auto-inserted a trailing comma.","solutions":["Open the file at the path in the error and fix the JSON syntax error cited in the message (line/column from the underlying SyntaxError).","Validate with a linter: `npx jsonlint <file>` or your editor's JSON language server to find the exact position.","Remove comments, trailing commas, and single quotes; ensure strings use double quotes.","If the file was truncated, restore from git: `git checkout HEAD -- <file>`."],"exampleFix":"// before (case.json — invalid)\n{\n  \"id\": \"slack-setup\",\n  // trailing comma below:\n  \"userMessage\": \"hi\",\n}\n// after\n{\n  \"id\": \"slack-setup\",\n  \"userMessage\": \"hi\"\n}","handlingStrategy":"try-catch","validationCode":"import { readFileSync } from 'fs';\nfunction tryParseJson(filePath: string): unknown {\n  try {\n    return JSON.parse(readFileSync(filePath, 'utf-8'));\n  } catch (e) {\n    throw new Error(`${filePath}: ${(e as Error).message}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  raw = JSON.parse(content);\n} catch (error) {\n  // already the path this loader takes — augment with file context\n  throw new Error(`Failed to parse discovery test case ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n}","preventionTips":["Lint all case JSON in CI (`jsonlint` or equivalent) so syntax errors fail before any code runs.","Configure editors to reject trailing commas / comments in `.json` files.","Use `git status` after merges to confirm no conflict markers leaked into JSON."],"tags":["discovery","test-case-config","json","validation","authoring"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}