{"record":{"id":"8d30638a688e4b54","repo":"n8n-io/n8n","slug":"iterations-must-be-1","errorCode":null,"errorMessage":"--iterations must be >= 1","messagePattern":"--iterations must be >= 1","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/evaluations/cli/build-mcp-manifest.ts","lineNumber":230,"sourceCode":"\t\t\t}\n\t\t\tcase '--suite':\n\t\t\t\tresult.suite = nextArg(argv, i, arg);\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase '-h':\n\t\t\tcase '--help':\n\t\t\t\treturn { helpRequested: true };\n\t\t\tdefault:\n\t\t\t\tif (arg.startsWith('--')) {\n\t\t\t\t\tthrow new Error(`Unknown flag: ${arg.split('=', 1)[0]} (use --help)`);\n\t\t\t\t}\n\t\t\t\tresult.slugs.push(arg);\n\t\t\t\ti += 1;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (result.iterations < 1) throw new Error('--iterations must be >= 1');\n\tif (result.concurrency < 1) throw new Error('--concurrency must be >= 1');\n\tif (result.maxAttempts < 1) throw new Error('--max-attempts must be >= 1');\n\tif (result.source === 'langtracer' && !result.suite) {\n\t\tthrow new Error('--source langtracer requires --suite <slug>');\n\t}\n\n\tmkdirSync(result.outputDir, { recursive: true });\n\tif (!result.manifestPath) result.manifestPath = join(result.outputDir, 'manifest.json');\n\tif (!result.logDir) result.logDir = join(result.outputDir, 'logs');\n\tconst base = result.manifestPath.replace(/\\.json$/, '');\n\tresult.statsPath = `${base}-stats.json`;\n\tmkdirSync(result.logDir, { recursive: true });\n\n\treturn { helpRequested: false, args: result };\n}\n\nfunction readJson(path: string, label: string): unknown {\n\tconst content = readFileSync(path, 'utf-8');","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/evaluations/cli/build-mcp-manifest.ts#L212-L248","documentation":"Thrown by parseArgs() (build-mcp-manifest.ts:230) when the parsed --iterations value (or -n shorthand) is less than 1. Iterations controls how many builds are produced per slug; zero or negative iterations is meaningless. Note: parseIntArg accepts any integer including 0 or negatives (parseInt('-1') is -1), so this boundary check catches non-positive values that parseIntArg would otherwise let through. The check fires after the parse loop.","triggerScenarios":"Passing `--iterations 0`, `-n 0`, `--iterations -1`, or a shell variable that resolved to a non-positive integer. parseIntArg only rejects NaN, so 0/negative reach this boundary check.","commonSituations":"A shell variable for iteration count is unset and defaulted to 0, a script computes iterations dynamically and produces 0 in some branch, or a typo passes a negative number.","solutions":["Pass a positive integer: --iterations 1 or higher.","If computing iterations dynamically, guard the value: `ITERATIONS=$(( COUNT > 0 ? COUNT : 1 ))` before passing.","Verify the shell variable is set and positive: `echo \"${ITERATIONS:?unset}\"`."],"exampleFix":"// before\npnpm eval:build-mcp-manifest --iterations 0\n// after\npnpm eval:build-mcp-manifest --iterations 1","handlingStrategy":"validation","validationCode":"function validateIterations(args: string[]): void {\n  for (let i = 0; i < args.length; i++) {\n    if ((args[i] === '-n' || args[i] === '--iterations')) {\n      const v = Number(args[i + 1]);\n      if (!Number.isInteger(v) || v < 1) {\n        throw new Error(`--iterations must be >= 1, got: ${args[i + 1]}`);\n      }\n    }\n  }\n}","typeGuard":"function isPositiveInt(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1;\n}","tryCatchPattern":null,"preventionTips":["Compute iteration counts with a floor of 1 in scripts: `ITER=$(( ITER > 0 ? ITER : 1 ))`.","Verify shell variables are set and positive before passing.","Avoid dynamic computations that can yield 0 in edge cases."],"tags":["cli","argument-validation","instance-ai","mcp-manifest"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}