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
The rednote search command's parseLimit requires --limit to coerce to a finite integer between 1 and 100 (no default coercion of null here; undefined becomes NaN). It throws ArgumentError naming the full valid range whenever the raw value is non-numeric, a float, or otherwise unparseable.
Source
Thrown at clis/rednote/search.js:16
/**
* Rednote search — international mirror of xiaohongshu/search.
*
* Reuses the DOM-extraction IIFE from `../xiaohongshu/search.js`; only the
* web host and the login-gate detection differ. See issue #1136 for the
* 1:1 comparison between the two frontends.
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { buildScrollUntilJs, buildSearchExtractJs, noteIdToDate } from '../xiaohongshu/search.js';
import { unwrapEvaluateResult } from '../xiaohongshu/shared.js';
function parseLimit(raw) {
const parsed = Number(raw);
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 requireSearchRows(payload) {
const rows = unwrapEvaluateResult(payload);
if (!Array.isArray(rows)) {
throw new CommandExecutionError('Unexpected Rednote search extraction payload shape; expected an array of rows.');
}
return rows;
}
/**
* Wait for search results or login wall using MutationObserver (max 5s).
*
* Differs from xiaohongshu by detecting a full-screen login modal insteadView on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer from 1 to 100, e.g. --limit 50
- Remember search has no implicit default here in some paths; always pass --limit explicitly
- Validate with Number.isInteger(Number(v)) && v>=1 && v<=100 before invoking
Example fix
// before
run(['rednote','search','--query','coffee','--limit', raw]);
// after
const n = Number(raw);
if (!Number.isInteger(n) || n < 1 || n > 100) throw new Error('limit must be 1-100');
run(['rednote','search','--query','coffee','--limit', n]); Defensive patterns
Strategy: validation
Validate before calling
const assertSearchLimit = (raw) => { const n = Number(raw); if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > 100) throw new Error('--limit must be an integer between 1 and 100'); return n; }; Type guard
const isValidSearchLimit = (v) => { const n = Number(v); return Number.isInteger(n) && n >= 1 && n <= 100; }; Try / catch
try { await runSearch({ query, limit }); } catch (e) { if (e instanceof ArgumentError && /between 1 and 100/.test(e.message)) { console.error('Usage: --limit 1..100'); process.exitCode = 2; return; } throw e; } Prevention
- Clamp user-provided limits to [1,100] before invoking search
- Always pass --limit explicitly for search (no reliable default in all paths)
- Remember search caps at 100; paginate with narrower queries for more
When it happens
Trigger: Calling rednote search with --limit 'abc', --limit 3.7, --limit '' , or omitting a value in a context where no default is applied so Number(undefined) = NaN.
Common situations: Copy-pasted commands where the number got dropped, scripts interpolating empty variables, users assuming search allows unlimited results (it is hard-capped at 100), or confusion with other rednote commands whose parseLimit defaults to 15/20.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- ${label} must be between ${min} and ${max}, got ${parsed}
- ${label} must be <= ${max}
- --${name} must be between ${min} and ${max}, got ${parsed}
- flomo memos --${name} must be between 1 and ${max}
- limit must be an integer between 1 and ${max}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4985de9a1981a00c.
Report an issue: GitHub.