jackwener/OpenCLI · error · ArgumentError

${name} must be <= ${max}

Error message

${name} must be <= ${max}

What it means

requireLimit also enforces an optional maximum. When a max option is provided and the parsed limit exceeds it, this ArgumentError is thrown telling the caller to lower the value. It exists to keep requests within API page-size limits instead of letting oversized requests fail downstream.

Source

Thrown at clis/pinterest/utils.js:33

/** Unwrap the { session, data } envelope some browser-bridge versions add. */
export function unwrapEvaluateResult(payload) {
  const isEnvelope = payload
    && typeof payload === 'object'
    && !Array.isArray(payload)
    && 'session' in payload
    && 'data' in payload;
  return isEnvelope ? payload.data : payload;
}

/** Validate a positive-integer limit (throws instead of silently clamping). */
export function requireLimit(value, { fallback, max, name = 'limit' }) {
  const parsed = Number(value ?? fallback);
  if (!Number.isInteger(parsed) || parsed <= 0) {
    throw new ArgumentError(`${name} must be a positive integer`, `e.g. --${name} 10`);
  }
  if (max && parsed > max) {
    throw new ArgumentError(`${name} must be <= ${max}`, `Lower --${name} to ${max} or below`);
  }
  return parsed;
}

/**
 * Fold a slug for comparison. Pinterest keeps non-ASCII characters in slugs (e.g.
 * `naive-café-中文`) and stores them NFC, but a pasted or keyboard-composed accent can arrive as
 * NFD, which compares unequal byte-wise.
 */
export function normalizeForMatch(value) {
  return String(value ?? '').normalize('NFC').trim().toLowerCase().replace(/\s+/g, ' ');
}

/**
 * Pinterest path prefixes that are site routes, not usernames. Without this a pin URL parses as
 * the board `pin/<id>` and fails with a confusing "could not resolve board".
 */
const RESERVED_PATH_ROOTS = new Set(['pin', 'search', 'ideas', 'today', 'settings', '_saved', 'news_hub', 'business']);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower the limit to at most the stated max, e.g. use 100 when max is 100
  2. Paginate: call repeatedly with limit <= max until results are exhausted
  3. Check the max configured at the call site (grep for requireLimit(...) options)
  4. If the max is legitimately too small for your use, use the paginating helper instead of raising max

Example fix

// before
const limit = requireLimit(input, { max: 100 }); // input = 500
// after
const limit = Math.min(Number(input) || 25, 100);
const clamped = requireLimit(limit, { max: 100 });
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 100;
const n = Number(input);
if (Number.isInteger(n) && n > MAX) {
  console.warn(`limit ${n} exceeds max ${MAX}, clamping`);
  input = MAX;
}

Type guard

const withinMax = (v, max) => Number.isSafeInteger(v) && v > 0 && v <= max;

Try / catch

try {
  limit = requireLimit(input, { max: 100 });
} catch (err) {
  if (err instanceof ArgumentError && /must be <=/.test(err.message)) {
    limit = 100; // clamp to max
  } else throw err;
}

Prevention

When it happens

Trigger: Calling requireLimit(value, { max: 100 }) with value = 500, or CLI input like --limit 1000 against a helper configured with a smaller max.

Common situations: Users guessing at a 'fetch everything' page size; copy-pasted limits from another API's docs; a config raised after the library tightened its max; confusion between item count and page count.

Related errors


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