jackwener/OpenCLI · error · ArgumentError
oeis ${label} must be a positive integer
Error message
oeis ${label} must be a positive integer What it means
requireBoundedInt normalizes a numeric CLI option (defaulting when undefined) and throws this ArgumentError when the value is not an integer greater than zero. The OEIS CLI uses it to validate options like `limit`, so callers never pass invalid paging/sizing values downstream. It fires before any network call, purely as input validation.
Source
Thrown at clis/oeis/utils.js:24
export const OEIS_BASE = 'https://oeis.org';
const UA = 'opencli-oeis-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';
// OEIS ids are A followed by 6 zero-padded digits (older entries use 6 by convention,
// modern entries can be longer; OEIS itself accepts any digits after A).
const SEQUENCE_ID_PATTERN = /^A\d{1,7}$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`oeis ${label} cannot be empty`);
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(`oeis ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`oeis ${label} must be <= ${maxValue}`);
}
return n;
}
export function requireSequenceId(value) {
const raw = String(value ?? '').trim().toUpperCase();
if (!raw) throw new ArgumentError('oeis sequence id is required (e.g. "A000045" for Fibonacci)');
// Tolerate common URL paste like `https://oeis.org/A000045`.
const stripped = raw.replace(/^HTTPS?:\/\/(?:WWW\.)?OEIS\.ORG\//, '').replace(/\/.*$/, '');
if (!SEQUENCE_ID_PATTERN.test(stripped)) {
throw new ArgumentError(
`oeis sequence id "${value}" is not a valid A-number`,
'Expected format: "A" + digits (e.g. "A000045").',
);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive whole number, e.g. `--limit 10`.
- Omit the option to use the built-in default value.
- If computing the value in a script, round with Math.floor() and clamp to >= 1 before calling.
Example fix
// before cli --limit 0 // after cli --limit 10
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(raw);
if (!Number.isInteger(n) || n <= 0) throw new Error(`--limit must be a positive integer, got: ${raw}`); Type guard
function isPositiveInt(v) { const n = typeof v === 'number' ? v : Number(v); return Number.isInteger(n) && n > 0; } Try / catch
try { const limit = requireBoundedInt(opts.limit, 10, 100); } catch (e) { console.error(e.message); process.exitCode = 1; } Prevention
- Validate numeric CLI flags at argument-parse time, before any I/O.
- Prefer omitting the flag to rely on the library default.
- Round/clamp computed values before passing them in.
When it happens
Trigger: Calling limit(value, ...) with a non-integer number (e.g. 2.5), a zero or negative number, or a string that Number() cannot coerce to a positive integer (e.g. limit('abc') or limit('')).
Common situations: Typing `--limit 0` or `--limit -5` on the CLI, pasting a float like `--limit 10.5`, or passing an empty string from a shell variable that was never set.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search query must not be empty
- arxiv author cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3f2041cf4708dc35.
Report an issue: GitHub.