jackwener/OpenCLI · error · ArgumentError

--limit must be an integer between 1 and 20

Error message

--limit must be an integer between 1 and 20

What it means

normalizeApprovalLimit coerces the --limit value with Number() and requires an integer in the inclusive range 1..20. Non-numeric strings, decimals, zero, negatives, and values above 20 all throw this ArgumentError.

Source

Thrown at clis/trae-cn/utils.js:95

      expanded.push('terminal', 'delete', 'keep');
      continue;
    }
    if (!['terminal', 'delete', 'keep'].includes(item)) {
      throw new ArgumentError('--approve-kinds must contain only terminal, delete, keep, or all');
    }
    expanded.push(item);
  }
  const unique = Array.from(new Set(expanded));
  if (unique.length === 0) {
    throw new ArgumentError('--approve-kinds must contain at least one approval kind');
  }
  return unique;
}

export function normalizeApprovalLimit(value, fallback = 1) {
  const limit = value === undefined || value === null ? fallback : Number(value);
  if (!Number.isInteger(limit) || limit < 1 || limit > 20) {
    throw new ArgumentError('--limit must be an integer between 1 and 20');
  }
  return limit;
}

export function ensurePrompt(text) {
  const prompt = typeof text === 'string' ? text : '';
  if (!prompt.trim()) {
    throw new ArgumentError('text must not be empty');
  }
  return prompt;
}

export function normalizeModelLabel(text) {
  return String(text || '').toLowerCase().replace(/[^a-z0-9.]+/g, '');
}

export function listOpenModelItemsScript() {
  return `

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer from 1 to 20, e.g. --limit 5
  2. Quote/validate the value in shell scripts before interpolation
  3. Check for stray units like '5x' or '5 ' in config files

Example fix

// before
--limit 50
// after
--limit 20
Defensive patterns

Strategy: validation

Validate before calling

function isValidLimit(v, fallback = 1) {
  if (v === undefined || v === null) return true;
  const n = Number(v);
  return Number.isInteger(n) && n >= 1 && n <= 20;
}

Type guard

const isValidLimit = (v) => Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 20;

Try / catch

try { limit = normalizeApprovalLimit(raw); } catch (e) { if (e instanceof ArgumentError) { console.error('Use --limit as an integer 1-20'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: --limit 0, --limit 25, --limit 2.5, --limit 'many', or --limit with whitespace-only text from a config value.

Common situations: Users assuming the limit is unbounded, or scripts interpolating empty/unset variables into the flag.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/48234bb2627ea3c9. Report an issue: GitHub.