jackwener/OpenCLI · error · ArgumentError
`endoflife ${label} must be a positive integer`
Error message
`endoflife ${label} must be a positive integer` What it means
requireBoundedInt coerces its input to a number and enforces it is an integer within (0, maxValue]. Non-integers, zero, negatives, NaN (e.g. non-numeric strings) throw an ArgumentError '<label> must be a positive integer'; values above the cap throw a separate 'must be <= max' error. Used for options like limit.
Source
Thrown at clis/endoflife/utils.js:34
throw new ArgumentError(
'endoflife product is required (e.g. "nodejs", "python", "ubuntu")',
'Use the slug visible at https://endoflife.date/<product>.',
);
}
if (!PRODUCT.test(s)) {
throw new ArgumentError(
`endoflife product "${value}" is not a valid endoflife.date slug`,
'Slugs are lowercase ASCII letters/digits/"._-", e.g. "nodejs", "python", "ubuntu".',
);
}
return s;
}
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(`endoflife ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`endoflife ${label} must be <= ${maxValue}`);
}
return n;
}
export async function eolFetch(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 endoflife.date is reachable from this network.',
);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive whole number within the option's documented maximum
- Clamp/round the value in your script: Math.max(1, Math.min(Math.floor(x), max))
- Check the source value isn't an empty or non-numeric string
- Omit the option to use the default value
Example fix
// before
product({ limit: 'all' }); // NaN -> error
// after
product({ limit: 20 }); Defensive patterns
Strategy: validation
Validate before calling
function toBoundedInt(v, def, max) {
const n = Number(v ?? def);
if (!Number.isInteger(n) || n <= 0 || n > max) throw new Error(`value must be an integer in 1..${max}`);
return n;
} Type guard
function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; } Try / catch
try {
await eolProduct('nodejs', { limit: opts.limit });
} catch (e) {
if (e instanceof ArgumentError && /positive integer|must be <=/.test(e.message)) { console.error('limit must be 1..max'); process.exitCode = 2; }
else throw e;
} Prevention
- Sanitize numeric options: Math.max(1, Math.min(Math.floor(Number(x) || def), max))
- Avoid locale-formatted number strings ('1,000') in arguments
- Never pass 0 or negative values expecting 'unlimited' — omit the option for defaults
- Document valid ranges in wrapper scripts and validate before invoking
When it happens
Trigger: Passing limit=0, limit=-5, limit='abc', limit=2.5, or an empty string that coerces to NaN when calling an endoflife CLI command that uses requireBoundedInt.
Common situations: Users typing '--limit 0' expecting unlimited, scripts computing a limit that becomes NaN from missing data, locale-formatted numbers ('1,000') that fail Number(), float results from division feeding the option.
Related errors
- endoflife product is required (e.g. "nodejs", "python", "ubu
- `endoflife product "${value}" is not a valid endoflife.date
- bbc topic "${args.topic}" is not supported
- bbc ${label} must be a positive integer
- bbc ${label} must be <= ${maxValue}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/86866c861f4ff4a4.
Report an issue: GitHub.