{"record":{"id":"a7b0d1ceafb57d74","repo":"yamadashy/repomix","slug":"invalid-number-for-top-files-len-v-must-b","errorCode":null,"errorMessage":"Invalid number for --top-files-len: '${v}'. Must be a non-negative integer.","messagePattern":"Invalid number for --top-files-len: '(.+?)'\\. Must be a non-negative integer\\.","errorType":"validation","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/cli/cliRun.ts","lineNumber":96,"sourceCode":"      .option(\n        '--token-count-tree [threshold]',\n        'Show file tree with token counts; optional threshold to show only files with ≥N tokens (e.g., --token-count-tree 100)',\n        (value: string | boolean) => {\n          if (typeof value === 'string') {\n            if (!/^\\d+$/.test(value)) {\n              throw new RepomixError(`Invalid token count threshold: '${value}'. Must be a non-negative integer.`);\n            }\n            return Number(value);\n          }\n          return value;\n        },\n      )\n      .option(\n        '--top-files-len <number>',\n        'Number of largest files to show in summary (default: 5, e.g., --top-files-len 20)',\n        (v: string) => {\n          if (!/^\\d+$/.test(v)) {\n            throw new RepomixError(`Invalid number for --top-files-len: '${v}'. Must be a non-negative integer.`);\n          }\n          return Number(v);\n        },\n      )\n      // Repomix Output Options\n      .optionsGroup('Repomix Output Options')\n      .option('-o, --output <file>', 'Output file path (default: repomix-output.xml, use \"-\" for stdout)')\n      .option('--style <type>', 'Output format: xml, markdown, json, or plain (default: xml)')\n      .addOption(\n        new Option(\n          '--output-file-path-style <style>',\n          'How file paths are shown in output: target-relative or cwd-relative (default: target-relative)',\n        ).choices(['target-relative', 'cwd-relative']),\n      )\n      .option(\n        '--parsable-style',\n        'Escape special characters to ensure valid XML/Markdown (needed when output contains code that breaks formatting)',\n      )","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/cli/cliRun.ts#L78-L114","documentation":"`--top-files-len` sets how many largest files appear in the summary. The CLI parses it with a strict `/^\\d+$/` check; anything else throws this RepomixError during argument parsing.","triggerScenarios":"Passing `--top-files-len` with a non-integer value: negative (`-1`), decimal (`2.5`), empty, or a stray token swallowed by the option (e.g. `--top-files-len --include` patterns where commander consumes the next flag).","commonSituations":"Typos (`--top-files-len 2O` with letter O), forgetting the value so it eats the next flag, or scripting with unquoted/unexpanded variables that resolve empty.","solutions":["Pass a non-negative integer: `--top-files-len 20`","Ensure the value immediately follows the flag and is not empty","Check variables used in scripts expand to valid integers"],"exampleFix":"// before\nrepomix --top-files-len -1\n// after\nrepomix --top-files-len 20","handlingStrategy":"validation","validationCode":"const i = process.argv.indexOf('--top-files-len');\nconst v = i !== -1 ? process.argv[i + 1] : undefined;\nif (v !== undefined && !/^\\d+$/.test(v)) {\n  throw new Error(`--top-files-len needs a non-negative integer, got: ${v}`);\n}","typeGuard":"const isNonNegativeInt = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isInteger(v) && v >= 0;","tryCatchPattern":"try {\n  parseArgv(argv);\n} catch (e) {\n  if (e instanceof RepomixError && e.message.includes('--top-files-len')) {\n    console.error('Usage: --top-files-len 20 (non-negative integer)');\n  }\n  process.exitCode = 1;\n}","preventionTips":["Always provide an explicit integer right after the flag","Validate script variables before interpolating into CLI args"],"tags":["cli","argument-validation","option-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}