jackwener/OpenCLI · warning · ArgumentError

--limit must be between 1 and 100, got ${parsed}

Error message

--limit must be between 1 and 100, got ${parsed}

What it means

parseCollectionLimit validates the --limit CLI flag for xiaohongshu collection commands. It throws ArgumentError when the value parses to a finite integer but falls outside the allowed range of 1-100. The library enforces this cap because the xiaohongshu collection API's page size is bounded server-side.

Source

Thrown at clis/xiaohongshu/collection-helpers.js:39

function isObject(value) {
    return value && typeof value === 'object' && !Array.isArray(value);
}

export function unwrapBrowserResult(payload) {
    if (isObject(payload) && 'session' in payload && 'data' in payload) {
        return payload.data;
    }
    return payload;
}

export function parseCollectionLimit(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;
}

export function readSelfUserIdFromState(state) {
    const unwrapped = unwrapBrowserResult(state);
    const user = unwrapped?.user?.userInfo;
    const info = user?._value ?? user ?? {};
    return toCleanString(info.user_id ?? info.userId ?? info.userID ?? '');
}

export function mapCollectionNote(entry, options = {}) {
    if (!isObject(entry))
        return null;
    const noteCard = entry.note_card ?? entry.noteCard ?? entry;
    const noteId = toCleanString(entry.note_id
        ?? entry.noteId
        ?? entry.id

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Set --limit to a value between 1 and 100
  2. Clamp the value in your script before invoking: Math.min(100, Math.max(1, n))
  3. If you need more than 100 notes, rely on pagination of collection pages instead of one large limit

Example fix

// before
const { execSync } = require('child_process');
execSync(`xhs collection ${userId} --limit ${count}`); // count=250 -> throws
// after
const safe = Math.min(100, Math.max(1, Number(count) || 20));
execSync(`xhs collection ${userId} --limit ${safe}`);
Defensive patterns

Strategy: validation

Validate before calling

function safeLimit(raw) { const n = Number(raw ?? 20); return Number.isFinite(n) && Number.isInteger(n) && n >= 1 && n <= 100 ? n : 20; }

Type guard

const isValidLimit = (v) => Number.isFinite(Number(v)) && Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 100;

Try / catch

try { const limit = parseCollectionLimit(raw); } catch (e) { if (e instanceof ArgumentError) { console.error(e.message); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Calling a collection command with --limit 0, --limit 101, --limit -5, or any numeric value outside 1-100 (e.g. --limit 999). Values that are non-numeric or non-integer (like 'abc' or 2.5) throw the sibling integer-message error instead.

Common situations: Users guessing the valid range and trying 0 or 200; scripts templating a page size from config without clamping; automations passing an unbounded count collected elsewhere.

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


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