jackwener/OpenCLI · error · ArgumentError
--limit must be an integer between 1 and 50, got ${JSON.stri
Error message
--limit must be an integer between 1 and 50, got ${JSON.stringify(raw)} What it means
parseCommentLimit validates the --limit argument of the rednote comments command before any page work happens. The value must be a finite integer; Number(raw ?? 20) defaulting to 20 means null/undefined is fine, but non-numeric strings (NaN), floats, and other junk hit this ArgumentError with the raw value JSON-stringified for diagnosis.
Source
Thrown at clis/rednote/comments.js:15
/**
* Rednote comments — international mirror of xiaohongshu/comments.
* Reuses the DOM-extraction IIFE from `../xiaohongshu/comments.js`.
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { buildCommentsExtractJs, normalizeCommentRows } from '../xiaohongshu/comments.js';
import { buildNoteUrl, parseNoteId } from '../xiaohongshu/note-helpers.js';
const REDNOTE_SIGNED_URL_HINT = 'Pass a full rednote.com note URL with xsec_token from search results or user/profile context.';
function parseCommentLimit(raw) {
const parsed = Number(raw ?? 20);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be an integer between 1 and 50, got ${JSON.stringify(raw)}`);
}
if (parsed < 1 || parsed > 50) {
throw new ArgumentError(`--limit must be between 1 and 50, got ${parsed}`);
}
return parsed;
}
cli({
site: 'rednote',
name: 'comments',
access: 'read',
description: 'Read comments from a rednote note (supports nested replies)',
domain: 'www.rednote.com',
strategy: Strategy.COOKIE,
navigateBefore: false,
args: [
{ name: 'note-id', required: true, positional: true, help: 'Full rednote note URL with xsec_token' },
{ name: 'limit', type: 'int', default: 20, help: 'Number of top-level comments (max 50)' },View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer string, e.g. --limit 20 (omit the flag entirely to use the default of 20).
- Check the variable being interpolated into --limit — an empty or malformed env/script variable is the usual culprit.
- Strip units/whitespace before passing: --limit "${COUNT%.*}" if a float creeps in from a calculation.
- Clamp programmatically before the call: Math.min(50, Math.max(1, Math.round(Number(raw)))).
Example fix
// before opencli rednote comments <note-url> --limit 10.5 // after opencli rednote comments <note-url> --limit 10
Defensive patterns
Strategy: validation
Validate before calling
function validCommentLimit(raw) {
if (raw === undefined || raw === null) return true; // defaults to 20
const n = Number(raw);
return Number.isFinite(n) && Number.isInteger(n);
}
if (!validCommentLimit(opts.limit)) throw new Error(`--limit must be an integer, got ${JSON.stringify(opts.limit)}`); Type guard
function isIntLimit(v) {
return typeof v === 'number' && Number.isInteger(v);
} Try / catch
try {
await run(['rednote', 'comments', noteUrl, '--limit', String(limit)]);
} catch (err) {
if (err instanceof ArgumentError && err.message.includes('--limit must be an integer')) {
// fall back to default limit
await run(['rednote', 'comments', noteUrl]);
} else throw err;
} Prevention
- Always pass --limit as a plain integer string; never interpolate raw user/env values unvalidated.
- Omit --limit entirely to use the default of 20.
- Sanitize inputs: Math.round(Number(x)) and check Number.isInteger before invoking.
- Watch for shell quoting turning '10.5' or '20x' into the argument.
- Validate upstream counters before forwarding them as --limit.
When it happens
Trigger: Calling the rednote comments command with --limit set to a non-integer or non-numeric value: e.g. --limit abc (NaN), --limit 10.5 (float), --limit '' (Number('') is 0 — actually passes this branch, fails range), --limit '20x', or a programmatic kwargs.limit of an object/array.
Common situations: Shell quoting mistakes passing '10.5' or 'all'; scripts interpolating an empty or malformed variable into --limit; CLI wrappers forwarding a string like 'null' or 'undefined'; fat-fingered values such as --limit 2.5.
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
- --${name} must be between ${min} and ${max}, got ${parsed}
- juejin ${label} must be <= ${maxValue}
- --limit must be an integer between 1 and 500
- --limit must be between 1 and 50, got ${parsed}
- youtube search limit must be <= ${MAX_LIMIT}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6988506e76b6be55.
Report an issue: GitHub.