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 pagination limit is an integer within [1, max], defaulting nullish input to def. It throws ArgumentError for non-integers (decimals, non-numeric strings, NaN) and out-of-range values, so downstream queries never request 0 or huge page sizes.
Source
Thrown at clis/dongchedi/utils.js:166
*/
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(/series\/(\d+)/) || raw.match(/^(\d+)$/);
if (!m) {
throw new ArgumentError(
`'${rawInput}' does not look like a dongchedi series id (a number, or a /auto/series/<id> URL)`,
);
}
return m[1];
}
/** Validate an integer limit in [1, max]. */
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;
}
/** Collapse whitespace and trim; returns '' for nullish. */
export function clean(s) {
return String(s == null ? '' : s).replace(/\s+/g, ' ').trim();
}
/** Truncate long review text for table display, keeping it on one line. */
export function snippet(s, max = 180) {
const t = clean(s);
return t.length > max ? `${t.slice(0, max)}…` : t;
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and the documented max, e.g. limit=20
- Omit the limit entirely to use the default (def)
- If you want all items, call repeatedly paginating instead of setting an unbounded limit
Example fix
// before
loadDoubanSubjectPhotos(page, id, { limit: 'all' });
// after
loadDoubanSubjectPhotos(page, id, { limit: 120 }); // or omit for default Defensive patterns
Strategy: validation
Validate before calling
const n = Number(value);
if (value != null && value !== '' && (!Number.isInteger(n) || n < 1 || n > max)) {
throw new Error(`limit must be an integer in [1, ${max}]`);
} Type guard
function isValidLimit(v, max) { const n = Number(v); return Number.isInteger(n) && n >= 1 && n <= max; } Try / catch
try { await list({ limit }); } catch (e) { if (e.name === 'ArgumentError') { limit = undefined; /* fall back to default */ } else throw e; } Prevention
- Clamp user input: Math.min(Math.max(1, parsed), max)
- Reject non-numeric strings like 'all' before calling
- Omit limit to use the library default
When it happens
Trigger: limit='10.5' or 'abc' (NaN), limit=0, negative numbers, limit greater than the endpoint's max, or a string with stray characters after Number() coercion.
Common situations: Parsing a CLI --limit flag that was given 'all' or 'max'; a config file with a float; an off-by-one attempt to 'fetch everything' with 0 or Infinity.
Related errors
- archive search limit must be <= 100
- coingecko derivatives limit must be <= 500
- limit must be <= 250 (CoinGecko per_page upper bound)
- limit must be an integer between 1 and 15 (dianping single p
- 'limit', 'must be a positive integer ≤ 200'
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/459dd7afa3cd3fbe.
Report an issue: GitHub.