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
parseLimit validates the --limit CLI option in the Reuters CLI. It throws ArgumentError when the raw value is supplied but cannot be interpreted as a finite integer (e.g. 'abc', '3.5', '10x'). This check runs before the range check, so non-numeric input never reaches the MIN/MAX comparison.
Source
Thrown at clis/reuters/utils.js:13
/**
* Shared helpers for the reuters adapter.
*/
import { ArgumentError } from '@jackwener/opencli/errors';
const MIN_LIMIT = 1;
const MAX_LIMIT = 40;
export function parseLimit(raw, fallback = 10) {
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;
}
/**
* Build the in-page IIFE that fetches the Reuters search API.
*
* Returns a raw envelope `{ ok, status, body, error? }` so that error-handling
* lives in node space (not silently swallowed by `catch(e) {}` inside the
* browser).
*/
export function buildSearchScript(query, count) {
return `
(async () => {
const apiQuery = JSON.stringify({View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer value for --limit, e.g. --limit 10.
- Remove surrounding quotes/units or stray characters from the value.
- If the value comes from a variable, echo it first to confirm it is a plain integer.
- Omit --limit entirely to use the default fallback of 10.
Example fix
// before reuters search "ai" --limit 3.5 // after reuters search "ai" --limit 3
Defensive patterns
Strategy: validation
Validate before calling
function isValidLimit(v) {
if (v === undefined || v === null || v === '') return true; // falls back to default
const n = Number(v);
return Number.isFinite(n) && Number.isInteger(n);
}
if (!isValidLimit(rawLimit)) throw new Error('limit must be an integer'); Type guard
const isInteger = (v) => typeof v === 'number' ? Number.isInteger(v) : Number.isFinite(Number(v)) && String(Number(v)) === String(v).trim();
Try / catch
try {
const limit = parseLimit(rawLimit);
} catch (err) {
if (err instanceof ArgumentError) {
console.error(`Invalid --limit: ${err.message}. Using default 10.`);
} else throw err;
} Prevention
- Validate numeric CLI args with a schema (zod/yargs number type) before dispatch.
- Echo interpolated shell variables to confirm they are clean integers.
- Prefer omitting --limit to accept the default.
- Add a smoke test running the CLI with a valid --limit.
When it happens
Trigger: Invoking the reuters CLI with --limit set to a non-integer string ('abc'), a decimal ('3.5'), or any value that Number() coerces to NaN/Infinity (e.g. --limit '', --limit 1e400, --limit '10x').
Common situations: Users pasting 'limit=5' style syntax, typos like 'lmit 5o', shell scripts interpolating empty or malformed variables into --limit, or passing floats copied from other tools.
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
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/af5906b309c8f43a.
Report an issue: GitHub.