jackwener/OpenCLI · error · ArgumentError
--limit must be between 1 and 100, got ${parsed}
Error message
--limit must be between 1 and 100, got ${parsed} What it means
parseLimit additionally range-checks the parsed integer: --limit must be between 1 and 100 inclusive. If the value parses as an integer but falls outside that range, this ArgumentError is thrown with the parsed value in the message. This caps scrape size and prevents zero/negative limits.
Source
Thrown at clis/xiaohongshu/search.js:330
!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,
option,
capability: value === definition.defaultValue
? ''View on GitHub (pinned to 49907e53dc)
Solutions
- Use a value between 1 and 100, e.g. --limit 100
- Clamp the value in the calling code: Math.min(100, Math.max(1, n))
- For larger result sets, paginate with multiple calls instead of raising the limit
Example fix
// before const limit = userRequested; // e.g. 500 // after const limit = Math.min(100, Math.max(1, Number(userRequested) || 20));
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(rawLimit ?? 20);
const clamped = Math.min(100, Math.max(1, Math.trunc(n)));
if (clamped !== n) console.warn(`--limit ${rawLimit} out of range, using ${clamped}`); Type guard
const isLimitInRange = (v) => Number.isInteger(v) && v >= 1 && v <= 100;
Try / catch
try {
limit = parseLimit(rawLimit);
} catch (e) {
if (e instanceof ArgumentError && /between 1 and 100/.test(e.message)) {
limit = Math.min(100, Math.max(1, Number(rawLimit) || 20));
} else throw e;
} Prevention
- Clamp user-provided limits to [1, 100] before invoking the CLI
- Paginate with repeated calls rather than inflating the limit
- Guard pagination loops so counters never reach 0 or negatives
- Document the 1–100 range where the option is exposed to end users
When it happens
Trigger: --limit 0, --limit -5, --limit 101, or --limit 1000 — any integer outside [1, 100].
Common situations: Pagination loops that increment a limit without clamping, users trying to fetch 'everything' with a huge limit, or off-by-one logic passing 0 meaning 'no extra'.
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 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/818be7681bb8f4d7.
Report an issue: GitHub.