jackwener/OpenCLI · error · ArgumentError
--limit must be an integer between 1 and 100, got ${JSON.str
Error message
--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)} What it means
parseLimit converts the --limit CLI argument (defaulting to 20) into an integer. If the raw value is not a finite number (e.g. 'abc' or '1,5'), it throws this ArgumentError with the raw value JSON-stringified. It is a strict argument-validation guard so downstream scraping only receives a usable count.
Source
Thrown at clis/xiaohongshu/search.js:327
const result = unwrapEvaluateResult(payload);
const diag = result?.diag;
if (!result || typeof result !== 'object' || Array.isArray(result) || !Array.isArray(result.rows) ||
!diag || typeof diag !== 'object' || Array.isArray(diag) ||
typeof diag.securityBlock !== 'boolean' || typeof diag.stopReason !== 'string' ||
!Number.isFinite(diag.scrollHeight) || diag.scrollHeight < 0 ||
!Number.isFinite(diag.clientHeight) || diag.clientHeight < 0 ||
!Number.isSafeInteger(diag.cardCount) || diag.cardCount < 0 ||
!(diag.feedClientHeight === null || (Number.isFinite(diag.feedClientHeight) && diag.feedClientHeight >= 0)) ||
!Number.isSafeInteger(diag.distinctCardTops) || diag.distinctCardTops < 0) {
throw new CommandExecutionError('Unexpected Xiaohongshu search harvest payload shape; expected rows plus typed diagnostics.');
}
result.rows = result.rows.map((row, index) => requireTrustedHarvestRow(row, index, webHost));
return result;
}
export function parseLimit(raw) {
const parsed = Number(raw ?? 20);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)}`);
}
if (parsed < 1 || parsed > 100) {
throw new ArgumentError(`--limit must be between 1 and 100, got ${parsed}`);
}
return parsed;
}
function resolveSearchFilters(kwargs) {
return SEARCH_FILTERS.map((definition) => {
const value = kwargs[definition.arg] ?? definition.defaultValue;
const option = typeof value === 'string' ? definition.options[value] : undefined;
if (!option) {
throw new ArgumentError(
`--${definition.arg} must be one of: ${Object.keys(definition.options).join(', ')}, got ${JSON.stringify(value)}`,
);
}
return {
group: definition.group,View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a plain integer string, e.g. --limit 20
- Quote/escape the value in the shell so spaces or special characters don't corrupt it
- Validate/trim the value in the calling script before forwarding it to the CLI
- If a default is desired, omit --limit entirely (defaults to 20)
Example fix
// before cli --search "coffee" --limit 3.5 // after cli --search "coffee" --limit 3
Defensive patterns
Strategy: validation
Validate before calling
const rawLimit = process.argv[/* --limit value */];
const n = Number(rawLimit);
if (!Number.isFinite(n) || !Number.isInteger(n)) {
throw new Error(`--limit must be an integer, got ${JSON.stringify(rawLimit)}`);
} Type guard
const isValidRawLimit = (v) => v === undefined || v === null || (typeof v === 'string' && v.trim() !== '' && Number.isInteger(Number(v)));
Try / catch
try {
limit = parseLimit(rawLimit);
} catch (e) {
if (e instanceof ArgumentError) {
console.error(e.message + ' — using default 20');
limit = 20;
} else throw e;
} Prevention
- Quote --limit values in shell scripts to avoid stray characters
- Sanitize interpolated variables before passing them as CLI args
- Prefer omitting --limit when the default (20) is acceptable
- Add CLI arg parsing with typed flags (e.g. a parser library) to catch this before the library does
When it happens
Trigger: Calling the CLI with --limit abc, --limit '' (empty string), --limit 3.5, or passing a non-numeric string programmatically into the limit option; Number() on such inputs yields NaN so the isFinite/isInteger check fails.
Common situations: Shell quoting mistakes (--limit "1 0"), copy-pasting values with units (--limit 20x), locale-formatted numbers with commas, or scripts interpolating undefined/malformed variables into the argument.
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/aeea573a3f3b9e40.
Report an issue: GitHub.