jackwener/OpenCLI · error · ArgumentError
tvmaze ${label} must be a positive integer
Error message
tvmaze ${label} must be a positive integer What it means
requireBoundedInt validates a numeric CLI option (by default 'limit') and throws ArgumentError when the value is not a positive integer. The tvmaze CLI uses it to sanitize user-supplied paging limits before building the API request URL. This error means the value passed (or its string form) failed Number.isInteger or was <= 0.
Source
Thrown at clis/tvmaze/utils.js:32
}
export function requireShowId(value) {
const raw = value;
const n = typeof raw === 'number' ? raw : Number(String(raw ?? '').trim());
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError(
'tvmaze show id is required and must be a positive integer',
'TVmaze show ids appear in the URL: https://www.tvmaze.com/shows/<id>/<slug>.',
);
}
return n;
}
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(`tvmaze ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`tvmaze ${label} must be <= ${maxValue}`);
}
return n;
}
export async function tvmazeFetch(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 api.tvmaze.com is reachable from this network.',
);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a whole number >= 1 (e.g. --limit 10)
- Omit the option entirely so the defaultValue is used
- Trim/validate any shell or config value before passing it; coerce with Number() and check Number.isInteger yourself
- If you need 'no limit', use the maximum allowed value rather than 0
Example fix
// before cli --limit 0 // after cli --limit 10 # or omit --limit to use the default
Defensive patterns
Strategy: validation
Validate before calling
function safeLimit(value, def = 10, max = 250) {
if (value === undefined || value === null) return def;
const n = Number(value);
if (!Number.isInteger(n) || n <= 0 || n > max) {
throw new RangeError(`limit must be an integer in [1, ${max}], got: ${value}`);
}
return n;
}
// call before the command: safeLimit(process.env.LIMIT) Type guard
function isPositiveInt(v) {
return typeof v === 'number'
? Number.isInteger(v) && v > 0
: Number.isInteger(Number(v)) && Number(v) > 0;
} Try / catch
try {
await cli(['tvmaze', 'list', '--limit', String(limit)]);
} catch (err) {
if (err.name === 'ArgumentError' && /must be a positive integer/.test(err.message)) {
console.error(`Invalid --limit '${limit}'; using default.`);
} else throw err;
} Prevention
- Validate numeric options with Number.isInteger at the entry point of your script
- Never use 0 or negative numbers as 'unlimited'; use the documented max
- Trim and sanitize env/config values before passing them to CLI flags
When it happens
Trigger: Passing --limit values like 0, -5, 2.5, 'abc', '10px', or an empty string to a tvmaze list/show command; also passing a numeric string with whitespace that Number() coerces to NaN.
Common situations: Typo in a script (limit=0 to mean 'unlimited'), shell variables that are unset or contain unit suffixes ('25 results'), or copying fractional values from a config file.
Related errors
- --adults must be an integer between 1 and 9, got ${JSON.stri
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- coingecko derivatives limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d5fe9aa6d246de6d.
Report an issue: GitHub.