jackwener/OpenCLI · error · ArgumentError

--limit must be an integer between ${MIN_LIMIT} and ${MAX_LI

Error message

--limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}

What it means

parseLimit() applies defaults (10) for missing values but enforces that --limit is an integer within [MIN_LIMIT=1, MAX_LIMIT=100]. Any non-numeric, non-integer, out-of-range, or NaN value throws this ArgumentError with the interpolated message '--limit must be an integer between 1 and 100'.

Source

Thrown at clis/barchart/greeks.js:36

function normalizeExpiration(value) {
    const expiration = String(value ?? '').trim();
    if (!expiration) return '';
    if (!/^\d{4}-\d{2}-\d{2}$/.test(expiration)) {
        throw new ArgumentError('--expiration must use YYYY-MM-DD format');
    }
    const parsed = new Date(`${expiration}T00:00:00Z`);
    if (Number.isNaN(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== expiration) {
        throw new ArgumentError('--expiration must be a valid calendar date');
    }
    return expiration;
}

function parseLimit(value) {
    if (value === undefined || value === null || value === '') return DEFAULT_LIMIT;
    const limit = Number(value);
    if (!Number.isInteger(limit) || limit < MIN_LIMIT || limit > MAX_LIMIT) {
        throw new ArgumentError(`--limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}`);
    }
    return limit;
}

function unwrapBrowserResult(value) {
    if (value && typeof value === 'object' && 'session' in value && 'data' in value) {
        return value.data;
    }
    return value;
}

cli({
    site: 'barchart',
    name: 'greeks',
    access: 'read',
    description: 'Barchart options greeks overview (IV, delta, gamma, theta, vega)',
    domain: 'www.barchart.com',
    strategy: Strategy.COOKIE,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use an integer between 1 and 100, e.g. --limit 50.
  2. Clamp the value in your script before calling: Math.min(100, Math.max(1, Math.round(n))).
  3. If you need more than 100 rows, paginate by adjusting offsets/queries rather than raising --limit.

Example fix

// before
--limit 250
// after
--limit 100  // max allowed; paginate for more rows
Defensive patterns

Strategy: validation

Validate before calling

const MIN_LIMIT = 1, MAX_LIMIT = 100;
function clampLimit(v, fallback = 10) {
  if (v === undefined || v === null || v === '') return fallback;
  const n = Number(v);
  if (!Number.isInteger(n) || n < MIN_LIMIT || n > MAX_LIMIT) {
    throw new Error(`--limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}`);
  }
  return n;
}

Type guard

function isValidLimit(v) {
  const n = Number(v);
  return Number.isInteger(n) && n >= 1 && n <= 100;
}

Try / catch

try {
  await greeks({ symbol, limit });
} catch (e) {
  if (e.name === 'ArgumentError' && e.message.includes('--limit')) {
    console.error('Use an integer 1-100 for --limit');
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing --limit 0, --limit 101, --limit abc, --limit 2.5, or a blank-but-nonempty value like --limit " " that Number() coerces to NaN.

Common situations: Trying to fetch more than 100 rows and assuming a larger limit is allowed; passing a float from a computed script; shell variable interpolation producing empty/odd values; copy-paste typos like a trailing comma.

Related errors


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