jackwener/OpenCLI · error · ArgumentError
-- must be between and , got
Error message
--${name} must be between ${min} and ${max}, got ${parsed} What it means
Thrown by parseStrictIntegerRange when a parsed integer falls outside the allowed [min,max] window (default MIN_LIMIT=1 to MAX_LIMIT=50 for list limits). The parser accepts the integer syntactically but enforces range bounds, raising ArgumentError with the actual bounds and offending value. Used by parseFlightLimit, parseHotelLimit, parseLimit, and parseListLimit.
Solutions
- Use a limit between 1 and 50 (the default bounds).
- Paginate: run multiple calls with offset/skip logic if you need more than 50 results.
- Check whether the specific command documents a different allowed range.
Example fix
// before
await runTrainList({ from, to, date, limit: 100 });
// after
const PAGE = 50;
await runTrainList({ from, to, date, limit: PAGE }); // paginate for more Defensive patterns
Strategy: validation
Validate before calling
const withinRange = (v, min = 1, max = 50) => { const n = Number(v); return Number.isInteger(n) && n >= min && n <= max; };
if (!withinRange(opts.limit)) opts.limit = Math.min(Math.max(Number(opts.limit) || 15, 1), 50); Type guard
const isBoundedInt = (v, min, max) => Number.isInteger(v) && v >= min && v <= max;
Try / catch
try { await run(opts); } catch (e) { if (e instanceof ArgumentError && /must be between/.test(e.message)) { opts.limit = 15; return run(opts); } throw e; } Prevention
- Clamp dynamic limits to [1, 50] before invoking
- Remember the default cap is 50; paginate for more results
- Never use 0 to mean 'unlimited' with these parsers
When it happens
Trigger: --limit 0 (below min) or --limit 51+ (above default max), e.g. --limit 100 requesting 100 results when the cap is 50; custom min/max ranges passed by other callers likewise reject out-of-window values.
Common situations: Users requesting large batches assuming no cap; scripts computing limits dynamically and exceeding 50; passing 0 to mean 'unlimited'; a caller supplying custom min/max that the value violates.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- --limit must be an integer between 1 and 500
- flomo memos -- must be between 1 and
- --index must be between 1 and
- Invalid interval: . Expected an integer from 0 to .
- juejin must be <=
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d1bec526702a4ef8.
Report an issue: GitHub.
Appendix: source
Thrown at clis/ctrip/utils.js:39
throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);
}
if (typeof raw === 'string' && /^(0|[1-9]\d*)$/.test(raw)) {
return Number(raw);
}
throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);
}
export function parseStrictPositiveInteger(name, raw) {
const parsed = parseStrictDecimalInteger(name, raw);
if (parsed > 0) return parsed;
throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);
}
export function parseStrictIntegerRange(name, raw, fallback, min = MIN_LIMIT, max = MAX_LIMIT) {
if (raw === undefined || raw === null || raw === '') return fallback;
const parsed = parseStrictDecimalInteger(name, raw);
if (parsed < min || parsed > max) {
throw new ArgumentError(`--${name} must be between ${min} and ${max}, got ${parsed}`);
}
return parsed;
}
export function parseLimit(raw, fallback = 15) {
return parseStrictIntegerRange('limit', raw, fallback);
}
export async function fetchSuggest(query, searchType) {
let response;
try {
response = await fetch(ENDPOINT, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
keyword: query,
searchType,
platform: 'online',View on GitHub (pinned to 49907e53dc)