jackwener/OpenCLI · error · ArgumentError

lichess must be <=

Error message

lichess ${label} must be <= ${maxValue}

What it means

This ArgumentError is thrown by `requireBoundedInt` when the value is a positive integer but exceeds `maxValue` for the given label. It caps how large a count the CLI will request, protecting both the user and the Lichess API.

Solutions

  1. Lower the limit to at most the maxValue stated in the error message
  2. Omit the limit to use the command's defaultValue
  3. Check the specific command's docs for its cap (maxValue differs per label)
  4. If you need more data, paginate with multiple calls at the allowed limit

Example fix

// before
await limit('drnik', 500); // throws if maxValue is e.g. 100
// after
await limit('drnik', Math.min(Number(raw) || 20, 100));
Defensive patterns

Strategy: validation

Validate before calling

function clampLimit(v, max = 100, fallback = 10) {
  if (v == null) return fallback;
  const n = Number(v);
  if (!Number.isInteger(n) || n < 1) throw new TypeError('limit must be a positive integer');
  if (n > max) throw new RangeError(`limit must be <= ${max}`);
  return n;
}
await limit(userArg, clampLimit(rawLimit, 100));

Type guard

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

Try / catch

try {
  await limit(userArg, rawLimit);
} catch (e) {
  if (e instanceof ArgumentError && /must be <=/.test(e.message)) {
    const max = Number(e.message.match(/<= (\d+)/)?.[1] ?? 'N/A');
    console.error(`Limit too high; retry with --limit ${max} or less.`);
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `limit()` (via `requireBoundedInt`) with a value above the command's configured maximum, e.g. `--limit 1000` when maxValue is smaller.

Common situations: Assuming unbounded limits; copying limits from another tool with a higher cap; wanting 'everything' and passing a huge number; misremembering the cap for a specific subcommand.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at clis/lichess/utils.js:53

    const raw = String(value ?? '').trim();
    if (!raw) throw new ArgumentError('lichess perf is required (e.g. "blitz", "bullet", "rapid")');
    if (!LICHESS_PERFS.has(raw)) {
        throw new ArgumentError(
            `lichess perf "${value}" is not recognised`,
            `Allowed values: ${[...LICHESS_PERFS].join(', ')}.`,
        );
    }
    return raw;
}

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

export async function lichessFetch(url, label) {
    let resp;
    try {
        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
    }
    catch (err) {
        throw new CommandExecutionError(
            `${label} request failed: ${err?.message ?? err}`,
            'Check that lichess.org is reachable from this network.',
        );
    }
    if (resp.status === 404) {
        throw new EmptyResultError(label, `Lichess returned 404 for ${url}.`);
    }

View on GitHub (pinned to 49907e53dc)