jackwener/OpenCLI · error · ArgumentError
${flagLabel} must be a non-negative integer
Error message
${flagLabel} must be a non-negative integer What it means
requireNonNegativeInt rejects values that are not integers >= 0 and throws ArgumentError with the flag label. It backs the stableSeconds flag (wait-for-stable duration). Negative numbers, fractions, and non-numeric input fail.
Source
Thrown at clis/chatgpt/utils.js:179
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) and
// weibo (#1568).
//
// `unwrapEvaluateResult` is a defensive ternary: it unwraps when the payload
// looks like an envelope, otherwise passes the value through unchanged so
// older bridge versions and primitive return values still work.
// ─────────────────────────────────────────────────────────────────────────────
export function unwrapEvaluateResult(payload) {View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer >= 0, e.g. --stable-seconds 3 (0 is allowed)
- Math.max(0, Math.round(value)) your computed value before invoking
- Parse env/config strings with Number.parseInt and validate before passing
- Catch ArgumentError and print its hint for the expected format
Example fix
// before --stable-seconds -2 // after --stable-seconds 0 // or any integer >= 0
Defensive patterns
Strategy: validation
Validate before calling
const n = Number.parseInt(raw, 10);
if (!Number.isInteger(n) || n < 0) throw new Error(`${label} must be a non-negative integer`); Type guard
function isNonNegativeInt(v) { return Number.isInteger(v) && v >= 0; } Try / catch
try { await run({ stableSeconds }); } catch (e) { if (e instanceof ArgumentError) { console.error(e.hint ?? e.message); process.exitCode = 2; } else throw e; } Prevention
- Clamp computed durations with Math.max(0, Math.round(x))
- Parse env strings to int before passing
- Remember 0 is valid, negatives are not
When it happens
Trigger: Passing a negative --stable-seconds, a decimal like 1.5, or an unparsed string/NaN into a command that validates stability wait time.
Common situations: Computing a delta that came out negative (end < start), misreading the flag as accepting floats, or shell env strings not converted to numbers.
Related errors
- ${flagLabel} must be a positive 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/648d547748f0ecb2.
Report an issue: GitHub.