jackwener/OpenCLI · error · ArgumentError
--limit must be an integer between ${MIN_LIMIT} and ${MAX_LI
Error message
--limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}, got ${JSON.stringify(raw)} What it means
parseListLimit validates the --limit option as an integer; this error is thrown when the value is non-numeric, non-finite, or a non-integer (e.g. 12.5, 'abc', Infinity). The message advertises the accepted range via MIN_LIMIT/MAX_LIMIT constants.
Source
Thrown at clis/trip/utils.js:55
const year = Number(m[1]);
const month = Number(m[2]);
const day = Number(m[3]);
if (month < 1 || month > 12 || day < 1 || day > 31) {
throw new ArgumentError(`--${name} has invalid month/day: ${value}`);
}
// Cross-check via UTC date math so 2026-02-30 doesn't pass.
const parsed = new Date(Date.UTC(year, month - 1, day));
if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) {
throw new ArgumentError(`--${name} is not a real calendar date: ${value}`);
}
return value;
}
export function parseListLimit(raw, fallback = 20) {
if (raw === undefined || raw === null || raw === '') return fallback;
const parsed = Number(raw);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}, got ${JSON.stringify(raw)}`);
}
if (parsed < MIN_LIMIT || parsed > MAX_LIMIT) {
throw new ArgumentError(`--limit must be between ${MIN_LIMIT} and ${MAX_LIMIT}, got ${parsed}`);
}
return parsed;
}
export function buildFlightSearchUrl(fromCode, toCode, date) {
const params = new URLSearchParams({
dcity: fromCode.toLowerCase(),
acity: toCode.toLowerCase(),
ddate: date,
triptype: 'ow',
class: 'y',
quantity: '1',
locale: 'en_US',
curr: 'USD',
});View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a whole number, e.g. --limit 50
- Remove formatting characters (commas, currency symbols, units) from the value
- Round or floor the value before passing: --limit $(python3 -c 'print(int(x))') or Math.floor() in a wrapper
- Check the accepted MIN_LIMIT/MAX_LIMIT in the CLI help to pick a valid integer
Example fix
// before clis-trip flights --from LON --to NYC --depart 2026-10-01 --limit 1,000 // after clis-trip flights --from LON --to NYC --depart 2026-10-01 --limit 100
Defensive patterns
Strategy: validation
Validate before calling
function isValidLimit(v) {
const n = Number(v);
return Number.isFinite(n) && Number.isInteger(n);
}
if (limit !== undefined && !isValidLimit(limit)) throw new Error(`--limit must be an integer, got ${JSON.stringify(limit)}`); Type guard
function isIntegerLike(v) {
const n = Number(v);
return Number.isFinite(n) && Number.isInteger(n);
} Try / catch
try {
runTripCli(['hotels', '--limit', limit]);
} catch (err) {
if (err instanceof ArgumentError && /--limit must be an integer/.test(err.message)) {
console.error(`Invalid --limit: ${err.message}. Pass a whole number.`);
process.exitCode = 2;
} else throw err;
} Prevention
- Coerce with Number() and check Number.isInteger before passing
- Strip formatting characters (commas, symbols, units) from config values
- Use Math.floor/Math.round for computed limits
- Document that --limit accepts plain integers only
When it happens
Trigger: Calling limit (which delegates to parseListLimit) with --limit abc, --limit 12.5, --limit NaN, --limit 1e999, or an object/array that Number() coerces to NaN.
Common situations: Decimal values pasted from configs; unit suffixes like '50+' or '1k'; a variable containing a formatted number with currency symbols or thousands separators ('1,000').
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
- juejin ${label} must be a positive decimal integer
- juejin ${label} must be a positive integer
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5e51547a6a0b0743.
Report an issue: GitHub.