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

parseLimit normalizes the --limit CLI option into a finite integer (defaulting to 20). It throws ArgumentError when the raw value cannot be coerced by Number() into a finite integer, e.g. strings like 'abc', '3.5', 'null', or ''. This fail-fast guard prevents downstream pagination code from receiving a nonsensical limit.

Source

Thrown at clis/rednote/notifications.js:28

 * `feed` hits on rednote.
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';

const NOTIFICATION_TYPES = new Set(['mentions', 'likes', 'connections']);

function parseNotificationType(raw) {
    const type = String(raw ?? 'mentions');
    if (!NOTIFICATION_TYPES.has(type)) {
        throw new ArgumentError(`--type must be one of mentions, likes, or connections, got ${JSON.stringify(raw)}`);
    }
    return type;
}

function parseLimit(raw) {
    const parsed = Number(raw ?? 20);
    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;
}

const READ_NOTIFICATIONS_JS = `
  (async (type) => {
    let pinia = null;
    const probe = (el) => el?.__vue_app__?.config?.globalProperties?.$pinia ?? null;
    pinia = probe(document.querySelector('#app'));
    if (!pinia) {
      for (const el of document.querySelectorAll('*')) {
        pinia = probe(el);
        if (pinia) break;
      }
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a plain positive integer, e.g. --limit 20
  2. If the flag comes from a shell variable, default it before use: LIMIT=${LIMIT:-20}
  3. Validate with Number.isInteger(Number(value)) before invoking the command

Example fix

// before
node cli.js rednote notifications --limit "$LIMIT"
// after
const LIMIT = Number.isInteger(Number(process.env.LIMIT)) ? Number(process.env.LIMIT) : 20;
node cli.js rednote notifications --limit ${LIMIT}
Defensive patterns

Strategy: validation

Validate before calling

function assertLimit(raw){ const n = Number(raw ?? 20); 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 isValidLimit = (v) => Number.isFinite(Number(v)) && Number.isInteger(Number(v));

Try / catch

try { await runNotifications({ limit }); } catch (e) { if (e instanceof ArgumentError && /--limit/.test(e.message)) { console.error('Fix --limit:', e.message); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Calling the rednote notifications command with --limit set to a non-numeric string ('abc'), a float ('2.5'), an empty string, or a value that JSON.stringify reveals as undefined/null passed explicitly.

Common situations: Typo in the flag value, shell variable interpolation producing an empty or quoted string (--limit "$MYVAR" where MYVAR is unset), scripting that forwards unvalidated user input, or pasting '20 notes' instead of 20.

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/4620524e55886dc9. Report an issue: GitHub.