{"record":{"id":"648d547748f0ecb2","repo":"jackwener/OpenCLI","slug":"flaglabel-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"${flagLabel} must be a non-negative integer","messagePattern":"(.+?) must be a non-negative integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/utils.js","lineNumber":179,"sourceCode":"    if (!text) {\n        throw new ArgumentError(\n            `${commandName} prompt cannot be empty`,\n            `Example: opencli ${commandName} \"hello\"`,\n        );\n    }\n    return text;\n}\n\nexport function requirePositiveInt(value, flagLabel, hint) {\n    if (!Number.isInteger(value) || value < 1) {\n        throw new ArgumentError(`${flagLabel} must be a positive integer`, hint);\n    }\n    return value;\n}\n\nexport function requireNonNegativeInt(value, flagLabel, hint) {\n    if (!Number.isInteger(value) || value < 0) {\n        throw new ArgumentError(`${flagLabel} must be a non-negative integer`, hint);\n    }\n    return value;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// page.evaluate envelope helpers.\n//\n// The browser bridge wraps every `page.evaluate(...)` return value in a\n// `{ session, data }` envelope. Adapters that read `.length` or\n// `Array.isArray(payload)` directly on the envelope silently see \"no data\" —\n// this matches the failure mode fixed for xiaohongshu/rednote (#1561) and\n// weibo (#1568).\n//\n// `unwrapEvaluateResult` is a defensive ternary: it unwraps when the payload\n// looks like an envelope, otherwise passes the value through unchanged so\n// older bridge versions and primitive return values still work.\n// ─────────────────────────────────────────────────────────────────────────────\nexport function unwrapEvaluateResult(payload) {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/utils.js#L161-L197","documentation":"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.","triggerScenarios":"Passing a negative --stable-seconds, a decimal like 1.5, or an unparsed string/NaN into a command that validates stability wait time.","commonSituations":"Computing a delta that came out negative (end < start), misreading the flag as accepting floats, or shell env strings not converted to numbers.","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"],"exampleFix":"// before\n--stable-seconds -2\n// after\n--stable-seconds 0   // or any integer >= 0","handlingStrategy":"validation","validationCode":"const n = Number.parseInt(raw, 10);\nif (!Number.isInteger(n) || n < 0) throw new Error(`${label} must be a non-negative integer`);","typeGuard":"function isNonNegativeInt(v) { return Number.isInteger(v) && v >= 0; }","tryCatchPattern":"try { await run({ stableSeconds }); } catch (e) { if (e instanceof ArgumentError) { console.error(e.hint ?? e.message); process.exitCode = 2; } else throw e; }","preventionTips":["Clamp computed durations with Math.max(0, Math.round(x))","Parse env strings to int before passing","Remember 0 is valid, negatives are not"],"tags":["argument-validation","cli-input","integer"],"backgroundTag":"invalid-flag-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}