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
- Pass a positive whole number (>= 1) for the limit
- Coerce and validate first: `Number.isInteger(Number(v)) && Number(v) > 0`
- Strip units/non-numeric characters from the input
- 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
- Parse CLI numeric flags with Number() and reject NaN before calling
- Strip units/suffixes ('10k', '5 games') from inputs
- Pass undefined (not '' or 0) to use the built-in default
- Add an argument-parsing layer (e.g. yargs with .number()) to catch this early
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
- ${label} must be a positive integer
- ${label} must be an integer between ${min} and ${max}, got $
- ${flagLabel} must be a positive integer
- ${flagLabel} must be a non-negative integer
- must be an integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/12c816dec0ff47d4.
Report an issue: GitHub.