jackwener/OpenCLI · error · ArgumentError
${label} must be an integer between ${min} and ${max}, got $
Error message
${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(value)} What it means
requireBoundedInt throws this ArgumentError when a CLI option must be an integer within [min, max] but the value is missing, non-numeric, non-integer, or out of range. Here it guards --answers-limit and --comments-limit against the Stack Exchange max page size (100). Values are string-coerced first so '--limit 5' arriving as '5' still validates.
Source
Thrown at clis/stackoverflow/read.js:90
*/
function coerceInt(value) {
if (value === undefined || value === null || value === '') return NaN;
const n = typeof value === 'number' ? value : Number(value);
return Number.isFinite(n) && Number.isInteger(n) ? n : NaN;
}
function requireMinInt(value, min, label) {
const n = coerceInt(value);
if (!Number.isInteger(n) || n < min) {
throw new ArgumentError(`${label} must be an integer >= ${min}, got ${JSON.stringify(value)}`);
}
return n;
}
function requireBoundedInt(value, min, max, label) {
const n = coerceInt(value);
if (!Number.isInteger(n) || n < min || n > max) {
throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(value)}`);
}
return n;
}
function byAcceptedThenScoreDesc(question, answers) {
const acceptedAnswerId = question.accepted_answer_id;
return answers
.slice()
.sort((a, b) => {
const aAccepted = a.is_accepted || (acceptedAnswerId && a.answer_id === acceptedAnswerId);
const bAccepted = b.is_accepted || (acceptedAnswerId && b.answer_id === acceptedAnswerId);
if (aAccepted !== bAccepted) return aAccepted ? -1 : 1;
return (b.score ?? 0) - (a.score ?? 0);
});
}
async function fetchMissingAcceptedAnswer(question, answers, label) {
const acceptedAnswerId = question.accepted_answer_id;View on GitHub (pinned to 49907e53dc)
Solutions
- Set the flag to an integer between 1 and 100 (SE_MAX_PAGE_SIZE), e.g. --answers-limit 10
- If more than 100 answers are needed, rely on the CLI's paging limits or paginate manually via the API
- Sanitize the value in wrapper scripts (parseInt and clamp) before invoking
Example fix
// before stackoverflow read 79935770 --answers-limit 500 // after stackoverflow read 79935770 --answers-limit 100
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(value);
if (!Number.isInteger(n) || n < 1 || n > 100) throw new Error(`limit must be an integer between 1 and 100, got ${value}`); Type guard
function isBoundedInt(value, min, max) {
const n = Number(value);
return Number.isInteger(n) && n >= min && n <= max;
} Try / catch
try {
await runCommand(['stackoverflow', 'read', id, '--answers-limit', String(limit)]);
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('must be an integer between')) {
console.error('Use an integer between 1 and 100 for --answers-limit/--comments-limit');
} else throw e;
} Prevention
- Cap limits at 100 (SE_MAX_PAGE_SIZE) — the API page size maximum
- Default to 10 answers / 5 comments when in doubt
- Guard against unset shell variables producing empty strings
- Use Math.min(100, Math.max(1, n)) to clamp before invoking
When it happens
Trigger: `stackoverflow read` invoked with --answers-limit or --comments-limit set to 0, negative, above 100, a float like 2.5, or a non-numeric string; value also fails when unset/empty (NaN).
Common situations: Trying to fetch more answers than the API page size allows (e.g. --answers-limit 500); shell passing empty string for an omitted flag; scripts building the command with an unset variable; typo like --comments-limit five.
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
- --limit must be a positive integer, got ${JSON.stringify(kwa
- `endoflife ${label} must be <= ${maxValue}`
- facebook search --limit must be an integer between 1 and ${M
- facebook search requires a non-empty query
- ${label} must be a path/URL or a JSON array: ${errorMessage(
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c5acbb8336e8df8c.
Report an issue: GitHub.