jackwener/OpenCLI · error · ArgumentError
--limit must be an integer between 1 and ${max} (got ${raw})
Error message
--limit must be an integer between 1 and ${max} (got ${raw}) What it means
ArgumentError thrown by parseLimitArg when --limit is provided but is not an integer within [1, max]. The CLI deliberately fails fast instead of clamping, so callers see the exact invalid value.
Source
Thrown at clis/coupang/utils.js:18
import { ArgumentError } from '@jackwener/opencli/errors';
/**
* Parse a positive integer arg (--limit / --page / --review-page).
*
* Throws ArgumentError on out-of-range / non-integer values rather than
* silently clamping. We prefer typed-fail-fast over silent clamping for the
* same reason as feedback_typed_fail_fast_for_adapters: callers cannot tell
* that their value was rewritten and end up confused why "limit=999" returned
* 50 rows.
*/
export function parseLimitArg(raw, fallback, max) {
if (raw === undefined || raw === null || raw === '') {
return fallback;
}
const num = Number(raw);
if (!Number.isInteger(num) || num < 1 || num > max) {
throw new ArgumentError(`--limit must be an integer between 1 and ${max} (got ${raw})`);
}
return num;
}
export function parsePageArg(raw, fallback) {
if (raw === undefined || raw === null || raw === '') {
return fallback;
}
const num = Number(raw);
if (!Number.isInteger(num) || num < 1) {
throw new ArgumentError(`--page must be a positive integer (got ${raw})`);
}
return num;
}
function itemKey(item) {
return item.url || item.product_id || `${item.title}:${item.price ?? ''}`;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and the max shown in the error
- Omit --limit entirely to use the fallback
- Clamp/validate your own input before invoking the CLI
- Check for stray whitespace or units in the value (e.g. '50 items')
Example fix
// before --limit 999 // after --limit 50
Defensive patterns
Strategy: validation
Validate before calling
function validLimit(raw, max) { const n = Number(raw); return Number.isInteger(n) && n >= 1 && n <= max ? n : null; } Type guard
function isValidLimit(v, max) { return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= max; } Try / catch
try { await cli.run(['coupang','search', q, '--limit', String(limit)]); } catch (e) { if (e instanceof ArgumentError && e.message.startsWith('--limit')) { limit = 20; return retry(); } throw e; } Prevention
- Always pass integers within the command's documented max
- Omit --limit when the default is acceptable
- Clamp user input before shelling out to the CLI
When it happens
Trigger: Passing --limit as a non-integer (e.g. 2.5), zero, negative, a non-numeric string ('many'), or a value above the command's max (e.g. --limit 999 when max is 50).
Common situations: Copy-pasting a limit from another tool with a different range; typo like `--limit=0`; scripting with an unset variable expanding to an empty/garbage string (empty string is OK — falls back — but whitespace is not).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
- --from and --to must differ; both resolved to ${fromStation.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3000e5172d7ac56d.
Report an issue: GitHub.