{"record":{"id":"4cd19b604755a838","repo":"n8n-io/n8n","slug":"name-must-be-a-positive-integer-got-raw","errorCode":null,"errorMessage":"${name} must be a positive integer, got \"${raw}\".","messagePattern":"(.+?) must be a positive integer, got \"(.+?)\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/evaluations/cli/pairwise.ts","lineNumber":115,"sourceCode":"\t\tmaxExamples: parsePositiveInt(get('--max-examples'), '--max-examples'),\n\t\texampleIds,\n\t\texamplesJsonl: get('--examples-jsonl'),\n\t\ttimeoutMs:\n\t\t\tparsePositiveNumber(get('--timeout-ms'), '--timeout-ms') ?? Number(DEFAULTS.TIMEOUT_MS),\n\t\toutputDir: get('--output-dir') ?? defaultOutputDir,\n\t\tjudgeModel: get('--judge-model') ?? 'claude-sonnet-4-5-20250929',\n\t\texperimentName: get('--experiment-name') ?? 'pairwise-evals-instance-ai',\n\t\tverbose: has('--verbose'),\n\t\tbaseUrl: get('--base-url') ?? process.env.N8N_EVAL_BASE_URL ?? 'http://localhost:5678',\n\t\tkeepWorkflows: has('--keep-workflows'),\n\t};\n}\n\nfunction parsePositiveInt(raw: string | undefined, name: string): number | undefined {\n\tif (raw === undefined || raw === '') return undefined;\n\tconst n = Number(raw);\n\tif (!Number.isFinite(n) || n <= 0 || !Number.isInteger(n)) {\n\t\tthrow new Error(`${name} must be a positive integer, got \"${raw}\".`);\n\t}\n\treturn n;\n}\n\nfunction parsePositiveNumber(raw: string | undefined, name: string): number | undefined {\n\tif (raw === undefined || raw === '') return undefined;\n\tconst n = Number(raw);\n\tif (!Number.isFinite(n) || n <= 0) {\n\t\tthrow new Error(`${name} must be a positive number, got \"${raw}\".`);\n\t}\n\treturn n;\n}\n\n// ---------------------------------------------------------------------------\n// Dataset loading\n// ---------------------------------------------------------------------------\n\ninterface DatasetExample {","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/evaluations/cli/pairwise.ts#L97-L133","documentation":"parsePositiveInt validates CLI numeric flags (e.g. --judges, --iterations) that must be positive integers. It rejects undefined/empty (returns undefined), but throws on NaN, non-finite, zero, negative, or fractional values. The error names the flag and shows the raw input.","triggerScenarios":"Passing `--iterations 0`, `--judges -1`, `--iterations 2.5`, or `--judges abc` to the pairwise CLI.","commonSituations":"Off-by-one in scripts generating the flag; copy/paste of a decimal where an integer is required; env-driven shells passing empty strings interpreted oddly.","solutions":["Re-run the CLI with a positive integer value for the named flag.","If the value comes from a script, coerce with Math.max(1, Math.floor(Number(x))) and validate before passing.","Check the flag's help text to confirm it expects an integer count."],"exampleFix":"// before: pnpm pairwise --iterations 0\n// after:  pnpm pairwise --iterations 3","handlingStrategy":"validation","validationCode":"function asPositiveInt(raw: string | undefined, name: string): number | undefined {\n  if (raw === undefined || raw === '') return undefined;\n  const n = Number(raw);\n  if (!Number.isFinite(n) || n <= 0 || !Number.isInteger(n))\n    throw new Error(`${name} must be a positive integer`);\n  return n;\n}","typeGuard":"const isPositiveInt = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isFinite(v) && v > 0 && Number.isInteger(v);","tryCatchPattern":null,"preventionTips":["Validate numeric args at the edge before invoking the CLI.","Document each flag's domain (count vs rate).","Use a CLI parser with built-in integer coercion."],"tags":["cli","validation","args"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}