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

  1. Pass a plain positive integer, e.g. --limit 15
  2. Trim/validate interpolated shell values before passing them
  3. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/0cc90976c5052bfe. Report an issue: GitHub.