jackwener/OpenCLI · error · ArgumentError

limit must be an integer between 1 and ${max}

Error message

limit must be an integer between 1 and ${max}

What it means

requireLimit() validates that a limit is an integer within 1..max (or supplies the default when null/empty). It throws this ArgumentError when the provided value is not an integer in that range — including non-numeric strings, floats, zero, or negatives.

Source

Thrown at clis/autohome/utils.js:101

export function normalizeSeriesId(rawInput) {
    const raw = String(rawInput || '').trim();
    if (!raw) throw new ArgumentError('series_id must be a non-empty value');
    const m = raw.match(/\/(?:s)?(\d+)(?:\/|$|\.)/) || raw.match(/^s?(\d+)$/);
    if (!m) {
        throw new ArgumentError(`'${rawInput}' does not look like an autohome series id (a number, or a k.autohome.com.cn/<id> URL)`);
    }
    return m[1];
}

export function clean(s) {
    return String(s == null ? '' : s).replace(/\s+/g, ' ').trim();
}

export function requireLimit(value, def, max) {
    const raw = value == null || value === '' ? def : value;
    const n = typeof raw === 'number' ? raw : Number(String(raw).trim());
    if (!Number.isInteger(n) || n < 1 || n > max) {
        throw new ArgumentError(`limit must be an integer between 1 and ${max}`);
    }
    return n;
}

export function requireStableId(value, label) {
    const id = String(value ?? '').trim();
    if (!/^\d+$/.test(id)) throw new CommandExecutionError(`${label} did not include a stable numeric id.`);
    return id;
}

export function requireText(value, label) {
    const text = clean(value);
    if (!text) throw new CommandExecutionError(`${label} did not include a stable text value.`);
    return text;
}

export function assertPlainObject(value, label) {
    if (!value || typeof value !== 'object' || Array.isArray(value)) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer between 1 and max (see the command's help for max)
  2. Omit the limit to use the default
  3. Coerce/validate the value yourself before calling, e.g. Number() plus Number.isInteger and range check

Example fix

// before
limit('20 items')
// after
limit(20)
Defensive patterns

Strategy: validation

Validate before calling

function isValidLimit(v, max) {
  const n = typeof v === 'number' ? v : Number(String(v ?? '').trim());
  return Number.isInteger(n) && n >= 1 && n <= max;
}
if (!isValidLimit(raw, 100)) throw new Error('limit must be an integer 1..100');

Try / catch

try {
  await cmd({ limit });
} catch (err) {
  if (err instanceof ArgumentError && /limit must be an integer/.test(err.message)) {
    console.error('Pass --limit as an integer between 1 and the command max');
  } else throw err;
}

Prevention

When it happens

Trigger: limit('abc'), limit(0), limit(-5), limit(2.5), or limit(max+1) on any command that accepts a --limit/limit option.

Common situations: CLI flag typoed (e.g. --limit=1O with letter O); parsing a string with units like '20 items'; off-by-one or unbounded upstream values exceeding the configured max.

Related errors


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