{"record":{"id":"27f91b09f8d5f151","repo":"jackwener/OpenCLI","slug":"flaglabel-must-be-a-positive-integer","errorCode":null,"errorMessage":"${flagLabel} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/utils.js","lineNumber":172,"sourceCode":"    if (value == null || value === '') return fallback;\n    const normalized = String(value).trim().toLowerCase();\n    return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on';\n}\n\nexport function requireNonEmptyPrompt(prompt, commandName) {\n    const text = String(prompt ?? '').trim();\n    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","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/utils.js#L154-L190","documentation":"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.","triggerScenarios":"Passing --timeout 0, --timeout -5, --timeout 2.5, --limit abc, or a value parsed to NaN/undefined into commands using timeout/limit flags.","commonSituations":"Setting timeout from an env var string that was never Number-parsed, using 0 assuming 'no limit', or decimal values copied from config docs.","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"],"exampleFix":"// before\nconst limit = process.env.LIMIT; // \"20\"\nawait run({ limit }); // string, not int\n// after\nconst limit = Number.parseInt(process.env.LIMIT, 10);\nif (!Number.isInteger(limit) || limit < 1) throw new Error('LIMIT must be a positive integer');","handlingStrategy":"validation","validationCode":"const n = Number.parseInt(raw, 10);\nif (!Number.isInteger(n) || n < 1) throw new Error(`${label} must be a positive integer`);","typeGuard":"function isPositiveInt(v) { return Number.isInteger(v) && v >= 1; }","tryCatchPattern":"try { await run({ timeout, limit }); } catch (e) { if (e instanceof ArgumentError) { console.error(e.hint ?? e.message); process.exitCode = 2; } else throw e; }","preventionTips":["Number.parseInt env/config strings before passing","Never use 0 to mean 'unlimited' for these flags","Avoid floats for timeout/limit"],"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"}