jackwener/OpenCLI · error · ArgumentError

limit must be a positive integer

Error message

limit must be a positive integer

What it means

parseLimit validates the user-supplied `limit` argument for gmail list/search commands. The value must coerce via Number() into a positive integer; otherwise ArgumentError is thrown. This is an input-validation guard so bad limits fail fast instead of producing garbage queries.

Source

Thrown at clis/gmail/utils.js:31

const PAGE_SIZE = 50;
const CAPTURE_WAIT_SECONDS = 10;
const MAX_BODY_CHARS = 20_000;

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() : '';

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer for limit (e.g. 20).
  2. Omit the limit argument entirely to use the default (20).
  3. Fix the calling script/config so it doesn't interpolate empty or non-numeric values.
  4. Clamp/validate user input before forwarding it to the command.

Example fix

// before
cli --limit all
// after
cli --limit 50
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(limitRaw);
if (!Number.isInteger(n) || n <= 0) {
  throw new Error(`limit must be a positive integer, got ${JSON.stringify(limitRaw)}`);
}

Try / catch

try {
  await gmailSearch({ limit });
} catch (e) {
  if (e instanceof ArgumentError && /limit must be a positive integer/.test(e.message)) {
    return gmailSearch({ limit: 20 }); // fall back to default
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing limit as a non-integer (e.g. 10.5), zero, a negative number, or a non-numeric string like 'all' or '' (empty string coerces to 0). Also passing null when no default applies is treated as fallback, but explicit bad strings fail.

Common situations: Typo in a config file (limit: "twenty"); shell scripts interpolating empty variables (`--limit $LIMIT` with unset LIMIT); copying an example with a float; user entering 0 expecting 'unlimited'.

Related errors


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