jackwener/OpenCLI · error · ArgumentError

weread-official: ${label} must be <= ${max}

Error message

weread-official: ${label} must be <= ${max}

What it means

requirePositiveInt accepts an optional { max } bound; when provided and the parsed integer exceeds it, the value is rejected with this message showing the cap. It protects downstream WeRead API calls from unreasonable page sizes / counts.

Source

Thrown at clis/weread-official/utils.js:275

}

export function requirePositiveInt(value, label, { defaultValue, max } = {}) {
    if (value === undefined || value === null || value === '') {
        if (defaultValue === undefined) {
            throw new ArgumentError(`weread-official: ${label} is required`);
        }
        return defaultValue;
    }
    const text = String(value).trim();
    if (!/^\d+$/.test(text)) {
        throw new ArgumentError(`weread-official: ${label} must be a positive integer`);
    }
    const n = Number(text);
    if (!Number.isSafeInteger(n) || n < 1) {
        throw new ArgumentError(`weread-official: ${label} must be a positive integer`);
    }
    if (max !== undefined && n > max) {
        throw new ArgumentError(`weread-official: ${label} must be <= ${max}`);
    }
    return n;
}

export function requireChoice(value, choices, label, defaultValue) {
    const text = String(value ?? defaultValue ?? '').trim();
    if (!choices.includes(text)) {
        throw new ArgumentError(`weread-official: ${label} must be one of: ${choices.join(', ')}`);
    }
    return text;
}

// ── Empty-result helper ────────────────────────────────────────────────────

/** Throw EmptyResultError with a stable command label. */
export function emptyResult(command, hint) {
    throw new EmptyResultError(`weread-official ${command}`, hint);
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower the value to at most the stated maximum, e.g. --count 100 when the message says 'must be <= 100'.
  2. Read the command's --help to learn the accepted range for the option.
  3. Paginate instead: request max repeatedly with offset/page advancement to reach a larger total.
  4. Update scripts to clamp: Math.min(requested, max) before invoking.

Example fix

// before
cli(['listNotebooks', '--count', '1000']);
// after
cli(['listNotebooks', '--count', '100']);
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 100; // mirror the limit enforced by the command
const n = Number(value);
if (!Number.isSafeInteger(n) || n < 1 || n > MAX) throw new Error(`count must be between 1 and ${MAX}`);

Type guard

function isWithinRange(v, max) { return Number.isSafeInteger(v) && v >= 1 && v <= max; }

Try / catch

try {
  await cli.run(['listNotebooks', '--count', requested]);
} catch (e) {
  const m = /must be <= (\d+)$/.exec(e.message || '');
  if (m) {
    await cli.run(['listNotebooks', '--count', m[1]]); // retry at the cap
  } else throw e;
}

Prevention

When it happens

Trigger: Passing --count 500 to a command whose call site invokes requirePositiveInt(value, label, { max: 100 }) — any n > max throws.

Common situations: Users assuming 'bigger is better' for limits; old scripts written before a server-side/API cap was introduced; confusing per-page vs total limits.

Related errors


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