jackwener/OpenCLI · error · ArgumentError
--limit must be a positive integer, got ${JSON.stringify(raw
Error message
--limit must be a positive integer, got ${JSON.stringify(raw)} What it means
The rednote user command's parseLimit defaults to 15 and throws ArgumentError when --limit cannot be coerced into a finite integer (non-numeric strings, floats, empty values). The raw input is echoed via JSON.stringify to make the offending value obvious.
Source
Thrown at clis/rednote/user.js:11
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
import { USER_SNAPSHOT_JS } from '../xiaohongshu/user.js';
import { extractXhsUserNotes, normalizeXhsUserId } from '../xiaohongshu/user-helpers.js';
const WEB_HOST = 'www.rednote.com';
function parseLimit(raw) {
const parsed = Number(raw ?? 15);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be a positive integer, got ${JSON.stringify(raw)}`);
}
if (parsed < 1) {
throw new ArgumentError(`--limit must be a positive integer, got ${parsed}`);
}
return parsed;
}
export const command = cli({
site: 'rednote',
name: 'user',
access: 'read',
description: 'Get public notes from a rednote user profile',
domain: WEB_HOST,
strategy: Strategy.COOKIE,
browser: true,
navigateBefore: false,
args: [
{ name: 'id', type: 'str', required: true, positional: true, help: 'User id or profile URL' },View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a plain positive integer, e.g. --limit 15
- Trim/validate interpolated shell values before passing them
- Rely on the built-in default by omitting --limit entirely
Example fix
// before
node cli.js rednote user --id "$UID_ARG" --limit "$LIMIT"
// after
LIMIT=${LIMIT:-15}; LIMIT=$(echo "$LIMIT" | tr -d '[:space:]')
node cli.js rednote user --id "$UID_ARG" --limit "$LIMIT" Defensive patterns
Strategy: validation
Validate before calling
function assertUserLimit(raw){ const n = Number(raw ?? 15); if (!Number.isFinite(n) || !Number.isInteger(n)) throw new Error(`--limit must be a positive integer, got ${JSON.stringify(raw)}`); return n; } Type guard
const isValidUserLimit = (v) => v === undefined || (Number.isInteger(Number(v)) && Number.isFinite(Number(v)));
Try / catch
try { await runUser({ id, limit }); } catch (e) { if (e instanceof ArgumentError && /--limit/.test(e.message)) { console.error('Pass an integer --limit or omit for default 15'); process.exitCode = 2; return; } throw e; } Prevention
- Omit --limit to use the built-in default of 15
- Sanitize shell-interpolated values (trim whitespace, strip units)
- Validate with Number.isInteger before invoking
When it happens
Trigger: Calling the rednote user command with --limit 'abc', --limit '2.5', --limit '', or an unset variable interpolated to empty string (Number('') is 0, but Number(' ') or 'abc' fail here).
Common situations: Shell variables that are unset or contain whitespace/units ('15 users'), config files exporting limit as text with stray characters, or typos like --limit l5.
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
- facebook marketplace-inbox --limit must be a positive intege
- Argument "content" is required.
- Jike search query cannot be empty
- --limit must be a positive integer
- --limit must be an integer between 1 and ${MAX_LIMIT}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/0cc90976c5052bfe.
Report an issue: GitHub.