jackwener/OpenCLI · error · ArgumentError

lichess ${label} must be a positive integer

Error message

lichess ${label} must be a positive integer

What it means

This ArgumentError is thrown by `requireBoundedInt` when the numeric argument (labeled via `label`, e.g. 'limit') is not a positive integer — it is non-numeric, fractional, zero, or negative. The library enforces this before using the value as a count.

Source

Thrown at clis/lichess/utils.js:50

}

export function requirePerf(value) {
    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.',
        );
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive whole number (>= 1) for the limit
  2. Coerce and validate first: `Number.isInteger(Number(v)) && Number(v) > 0`
  3. Strip units/non-numeric characters from the input
  4. Rely on the defaultValue by passing `undefined` instead of an invalid value

Example fix

// before
await limit('drnik', '0'); // throws: must be a positive integer
// after
const n = Number(raw);
if (!Number.isInteger(n) || n < 1) throw new Error('limit must be >= 1');
await limit('drnik', n);
Defensive patterns

Strategy: validation

Validate before calling

function toPositiveInt(v, fallback) {
  if (v == null) return fallback;
  const n = typeof v === 'number' ? v : Number(String(v).trim());
  if (!Number.isInteger(n) || n < 1) throw new TypeError(`limit must be a positive integer, got: ${v}`);
  return n;
}
await limit(userArg, toPositiveInt(rawLimit, 10));

Type guard

function isPositiveInt(v) {
  return typeof v === 'number' && Number.isInteger(v) && v > 0;
}

Try / catch

try {
  await limit(userArg, rawLimit);
} catch (e) {
  if (e instanceof ArgumentError && /positive integer/.test(e.message)) {
    console.error('The limit must be a whole number >= 1, e.g. --limit 10');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `limit()` (via `requireBoundedInt`) with e.g. `0`, `-5`, `'abc'`, `2.5`, or `NaN`. Note `Number('')` is 0, so an empty string also fails.

Common situations: CLI flags like `--limit 0` or `--limit -1`; passing a string with units ('10 games'); decimals from config files; unset variables coerced to NaN.

Related errors


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