jackwener/OpenCLI · error · ArgumentError
${flagLabel} must be a positive integer
Error message
${flagLabel} must be a positive integer What it means
requirePositiveInt rejects values that are not integers >= 1 and throws ArgumentError with the flag label and a hint. It is used by timeout and limit flags in chatgpt commands. Non-integer types, zero, negatives, and non-numeric strings all fail.
Source
Thrown at clis/chatgpt/utils.js:172
if (value == null || value === '') return fallback;
const normalized = String(value).trim().toLowerCase();
return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on';
}
export function requireNonEmptyPrompt(prompt, commandName) {
const text = String(prompt ?? '').trim();
if (!text) {
throw new ArgumentError(
`${commandName} prompt cannot be empty`,
`Example: opencli ${commandName} "hello"`,
);
}
return text;
}
export function requirePositiveInt(value, flagLabel, hint) {
if (!Number.isInteger(value) || value < 1) {
throw new ArgumentError(`${flagLabel} must be a positive integer`, hint);
}
return value;
}
export function requireNonNegativeInt(value, flagLabel, hint) {
if (!Number.isInteger(value) || value < 0) {
throw new ArgumentError(`${flagLabel} must be a non-negative integer`, hint);
}
return value;
}
// ─────────────────────────────────────────────────────────────────────────────
// page.evaluate envelope helpers.
//
// The browser bridge wraps every `page.evaluate(...)` return value in a
// `{ session, data }` envelope. Adapters that read `.length` or
// `Array.isArray(payload)` directly on the envelope silently see "no data" —
// this matches the failure mode fixed for xiaohongshu/rednote (#1561) andView on GitHub (pinned to 49907e53dc)
Solutions
- Pass a whole number >= 1, e.g. --timeout 30 --limit 10
- Number.parseInt your env/config value before passing it and check Number.isInteger
- If you want 'unlimited', check the command docs for a dedicated flag instead of 0
- Catch ArgumentError and surface its hint, which shows the expected format
Example fix
// before
const limit = process.env.LIMIT; // "20"
await run({ limit }); // string, not int
// after
const limit = Number.parseInt(process.env.LIMIT, 10);
if (!Number.isInteger(limit) || limit < 1) throw new Error('LIMIT must be a positive integer'); Defensive patterns
Strategy: validation
Validate before calling
const n = Number.parseInt(raw, 10);
if (!Number.isInteger(n) || n < 1) throw new Error(`${label} must be a positive integer`); Type guard
function isPositiveInt(v) { return Number.isInteger(v) && v >= 1; } Try / catch
try { await run({ timeout, limit }); } catch (e) { if (e instanceof ArgumentError) { console.error(e.hint ?? e.message); process.exitCode = 2; } else throw e; } Prevention
- Number.parseInt env/config strings before passing
- Never use 0 to mean 'unlimited' for these flags
- Avoid floats for timeout/limit
When it happens
Trigger: Passing --timeout 0, --timeout -5, --timeout 2.5, --limit abc, or a value parsed to NaN/undefined into commands using timeout/limit flags.
Common situations: Setting timeout from an env var string that was never Number-parsed, using 0 assuming 'no limit', or decimal values copied from config docs.
Related errors
- ${flagLabel} must be a non-negative integer
- archive snapshots url cannot be empty
- archive snapshots limit must be a positive integer
- archive snapshots limit must be <= 1000
- archive snapshots ${key} must be a digit-only timestamp (YYY
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/27f91b09f8d5f151.
Report an issue: GitHub.