yamadashy/repomix · error · RepomixError

Invalid number for --top-files-len: '${v}'. Must be a non-ne

Error message

Invalid number for --top-files-len: '${v}'. Must be a non-negative integer.

What it means

`--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.

Source

Thrown at src/cli/cliRun.ts:96

      .option(
        '--token-count-tree [threshold]',
        'Show file tree with token counts; optional threshold to show only files with ≥N tokens (e.g., --token-count-tree 100)',
        (value: string | boolean) => {
          if (typeof value === 'string') {
            if (!/^\d+$/.test(value)) {
              throw new RepomixError(`Invalid token count threshold: '${value}'. Must be a non-negative integer.`);
            }
            return Number(value);
          }
          return value;
        },
      )
      .option(
        '--top-files-len <number>',
        'Number of largest files to show in summary (default: 5, e.g., --top-files-len 20)',
        (v: string) => {
          if (!/^\d+$/.test(v)) {
            throw new RepomixError(`Invalid number for --top-files-len: '${v}'. Must be a non-negative integer.`);
          }
          return Number(v);
        },
      )
      // Repomix Output Options
      .optionsGroup('Repomix Output Options')
      .option('-o, --output <file>', 'Output file path (default: repomix-output.xml, use "-" for stdout)')
      .option('--style <type>', 'Output format: xml, markdown, json, or plain (default: xml)')
      .addOption(
        new Option(
          '--output-file-path-style <style>',
          'How file paths are shown in output: target-relative or cwd-relative (default: target-relative)',
        ).choices(['target-relative', 'cwd-relative']),
      )
      .option(
        '--parsable-style',
        'Escape special characters to ensure valid XML/Markdown (needed when output contains code that breaks formatting)',
      )

View on GitHub (pinned to f465ad9093)

Solutions

  1. Pass a non-negative integer: `--top-files-len 20`
  2. Ensure the value immediately follows the flag and is not empty
  3. Check variables used in scripts expand to valid integers

Example fix

// before
repomix --top-files-len -1
// after
repomix --top-files-len 20
Defensive patterns

Strategy: validation

Validate before calling

const i = process.argv.indexOf('--top-files-len');
const v = i !== -1 ? process.argv[i + 1] : undefined;
if (v !== undefined && !/^\d+$/.test(v)) {
  throw new Error(`--top-files-len needs a non-negative integer, got: ${v}`);
}

Type guard

const isNonNegativeInt = (v: unknown): v is number =>
  typeof v === 'number' && Number.isInteger(v) && v >= 0;

Try / catch

try {
  parseArgv(argv);
} catch (e) {
  if (e instanceof RepomixError && e.message.includes('--top-files-len')) {
    console.error('Usage: --top-files-len 20 (non-negative integer)');
  }
  process.exitCode = 1;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29). Data as JSON: /api/errors/a7b0d1ceafb57d74. Report an issue: GitHub.