jackwener/OpenCLI · error · ArgumentError

limit must be <= ${max}

Error message

limit must be <= ${max}

What it means

parseLimit also enforces an upper bound: the limit may not exceed max (the command's configured maximum, e.g. 200). This protects the browser capture pipeline from oversized requests. Exceeding it throws ArgumentError with the allowed maximum in the message.

Source

Thrown at clis/gmail/utils.js:34

export function unwrapBrowserResult(value, label = 'browser probe') {
  if (value && typeof value === 'object' && !Array.isArray(value) && 'session' in value) {
    if (typeof value.session === 'string' && Object.prototype.hasOwnProperty.call(value, 'data')) {
      return value.data;
    }
    throw new CommandExecutionError(`Gmail ${label} returned a malformed Browser Bridge envelope`);
  }
  return value;
}

export function parseLimit(raw, fallback = DEFAULT_LIMIT, max = MAX_LIMIT) {
  const value = raw ?? fallback;
  const limit = Number(value);
  if (!Number.isInteger(limit) || limit <= 0) {
    throw new ArgumentError('limit must be a positive integer');
  }
  if (limit > max) {
    throw new ArgumentError(`limit must be <= ${max}`);
  }
  return limit;
}

export function parseAccount(raw) {
  const value = raw ?? 0;
  const account = Number(value);
  if (!Number.isInteger(account) || account < 0 || account > 20) {
    throw new ArgumentError('account must be an integer between 0 and 20');
  }
  return account;
}

function cleanString(value) {
  return typeof value === 'string' ? value.trim() : '';
}

function gmailDate(value, label) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Reduce limit to the documented maximum (see the command's help text, e.g. 1-200).
  2. Clamp the value in the calling code: limit = Math.min(limit, 200).
  3. Paginate: issue multiple calls with limit=max and offset/continuation instead of one huge request.

Example fix

// before
cli --limit 1000
// after
cli --limit 200  // max allowed
Defensive patterns

Strategy: validation

Validate before calling

const MAX_LIMIT = 200;
const limit = Math.min(Math.max(1, Math.trunc(Number(raw) || 20)), MAX_LIMIT);

Try / catch

try {
  await gmailSearch({ limit });
} catch (e) {
  if (e instanceof ArgumentError && /limit must be <=/.test(e.message)) {
    const max = Number(e.message.match(/<= (\d+)/)?.[1] ?? 200);
    return gmailSearch({ limit: max });
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling a gmail thread query with limit > max, e.g. `--limit 500` when MAX_LIMIT is 200, or a script computing a large batch size without clamping.

Common situations: Users assuming 'more is fine' and setting limit=1000; scripts that pass total mailbox counts as limit; callers unaware the command documented a 1-200 range.

Related errors


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