jackwener/OpenCLI · error · ArgumentError

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

Error message

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

What it means

The second branch of parseCommentLimit: the value parsed as a finite integer but is outside the allowed range of 1–50, so the library throws ArgumentError with the parsed number. This guards both the API (page extraction cost) and row-count expectations; 0, negatives, and anything above 50 land here.

Source

Thrown at clis/rednote/comments.js:18

/**
 * 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)' },
        { name: 'with-replies', type: 'boolean', default: false, help: 'Include nested replies; reply_to is the direct target shown by the page' },
    ],
    columns: ['rank', 'author', 'text', 'likes', 'time', 'is_reply', 'reply_to', 'images'],

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer in [1, 50]; omit --limit to use the default of 20.
  2. Clamp the value before invoking: Math.min(50, Math.max(1, parsed)).
  3. Fix upstream logic producing 0 or oversized counts instead of forwarding them as --limit.
  4. If you genuinely need more comments, page through the command multiple times rather than raising --limit.

Example fix

// before
opencli rednote comments <note-url> --limit 100
// after
opencli rednote comments <note-url> --limit 50
Defensive patterns

Strategy: validation

Validate before calling

function clampLimit(raw, min = 1, max = 50) {
  const n = Math.round(Number(raw ?? 20));
  if (!Number.isFinite(n)) return 20;
  return Math.min(max, Math.max(min, n));
}
const limit = clampLimit(opts.limit);

Type guard

function isValidLimit(v) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 50;
}

Try / catch

try {
  await run(['rednote', 'comments', noteUrl, '--limit', String(limit)]);
} catch (err) {
  if (err instanceof ArgumentError && err.message.includes('--limit must be between 1 and 50')) {
    await run(['rednote', 'comments', noteUrl, '--limit', '50']); // clamp to max
  } else throw err;
}

Prevention

When it happens

Trigger: --limit 0, --limit -5, or --limit 51+ on the rednote comments command; also --limit '' (Number('') === 0 → integer, range check fails) and --limit 999999.

Common situations: Scripts computing a limit from a count that turned out to be 0 (e.g. no results upstream); users assuming 'more is fine' and passing 100; copy-pasted configs from other tools with different maxima; shell variable defaulting to empty string, which parses as 0.

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/48dba0119a264dde. Report an issue: GitHub.