jackwener/OpenCLI · error · ArgumentError

mdn limit must be <= ${maxValue}

Error message

mdn limit must be <= ${maxValue}

What it means

requireBoundedInt also enforces an upper bound: if the parsed integer exceeds maxValue, it throws this ArgumentError with the cap interpolated. This prevents oversized requests to the MDN search API.

Source

Thrown at clis/mdn/search.js:26

const MDN_BASE = 'https://developer.mozilla.org';
const UA = 'opencli-mdn-adapter (+https://github.com/jackwener/opencli)';
const ALLOWED_LOCALES = new Set(['en-US', 'de', 'es', 'fr', 'ja', 'ko', 'pt-BR', 'ru', 'zh-CN', 'zh-TW']);

function requireString(value, label) {
    const s = String(value ?? '').trim();
    if (!s) throw new ArgumentError(`mdn ${label} cannot be empty`);
    return s;
}

function requireBoundedInt(value, defaultValue, maxValue) {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError('mdn limit must be a positive integer');
    }
    if (n > maxValue) {
        throw new ArgumentError(`mdn limit must be <= ${maxValue}`);
    }
    return n;
}

function requireLocale(value) {
    const s = String(value ?? 'en-US').trim();
    if (!ALLOWED_LOCALES.has(s)) {
        throw new ArgumentError(
            `mdn locale "${value}" is not supported`,
            `Allowed locales: ${[...ALLOWED_LOCALES].join(' / ')}`,
        );
    }
    return s;
}

cli({
    site: 'mdn',
    name: 'search',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower the limit to at most the stated maximum in the error message.
  2. Inspect the adapter's call site to find maxValue (e.g. clis/mdn/search.js where limit is passed) and comply.
  3. Clamp the value in your script: Math.min(limit, maxAllowed).
  4. Paginate with multiple smaller searches instead of one huge limit.

Example fix

// before
await mdnSearch({ query: 'array map', limit: 500 });
// after
const MAX = 50;
await mdnSearch({ query: 'array map', limit: Math.min(500, MAX) });
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(rawLimit);
if (Number.isInteger(n) && n > MAX_LIMIT) throw new RangeError(`limit must be <= ${MAX_LIMIT}`);

Type guard

function isWithinLimit(v, max) { return Number.isInteger(v) && v > 0 && v <= max; }

Try / catch

try { await mdnSearch({ query, limit }); } catch (e) { const m = /limit must be <= (\d+)/.exec(e.message); if (m) { limit = +m[1]; return retry(); } throw e; }

Prevention

When it happens

Trigger: Passing a limit larger than the adapter's maximum allowed value (e.g. --limit 1000 when maxValue is smaller) to mdn search.

Common situations: Users assuming the API accepts unlimited page sizes; scripts passing fetched-count totals as a limit; copying limits from other MDN tooling with different caps.

Related errors


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