jackwener/OpenCLI · error · ArgumentError
--limit must be a positive integer, got ${parsed}
Error message
--limit must be a positive integer, got ${parsed} What it means
parseLimit for the rednote user command throws ArgumentError when the value is a valid integer but less than 1 (0 or negative). Unlike notifications (default 20), this parser defaults to 15 when the option is omitted; an explicit out-of-range integer still fails here.
Source
Thrown at clis/rednote/user.js:14
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' },
{ name: 'limit', type: 'int', default: 15, help: 'Number of notes to return' },
],
columns: ['id', 'title', 'type', 'likes', 'url'],View on GitHub (pinned to 49907e53dc)
Solutions
- Pass --limit >= 1 or omit the flag to use the default of 15
- Clamp before invoking: Math.max(1, n)
- Fix generating scripts to skip the call entirely when the computed count is 0
Example fix
// before const remaining = quota - used; // may be 0 run(['rednote','user','--id',id,'--limit',remaining]); // after const remaining = Math.max(1, quota - used); run(['rednote','user','--id',id,'--limit',remaining]);
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(raw ?? 15); if (Number.isInteger(n) && n < 1) throw new Error(`--limit must be >= 1, got ${n}`); Type guard
const isPositiveUserLimit = (v) => Number.isInteger(v) && v >= 1;
Try / catch
try { await runUser({ id, limit }); } catch (e) { if (e instanceof ArgumentError && /positive integer/.test(e.message)) { return runUser({ id, limit: Math.max(1, limit) }); } throw e; } Prevention
- Skip the call outright when a computed count is 0 instead of passing 0
- Clamp with Math.max(1, n) in wrapper scripts
- Treat 0/negative limits as 'use default' rather than 'none'
When it happens
Trigger: Passing --limit 0 or a negative number (e.g. --limit -3) to the rednote user command. String '0' also coerces to 0 and triggers this branch.
Common situations: Scripts computing a remaining-count that reached 0 and still calling the command, users expecting 0 to mean 'no limit' or 'skip', template variables defaulting to 0.
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/53bf1e11e2b6b6e5.
Report an issue: GitHub.