{"record":{"id":"041973d0c06e40ae","repo":"jackwener/OpenCLI","slug":"osv-label-must-be-a-positive-integer","errorCode":null,"errorMessage":"osv ${label} must be a positive integer","messagePattern":"osv (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/osv/utils.js","lineNumber":78,"sourceCode":"        throw new ArgumentError(\n            'osv --ecosystem is required when querying by package',\n            `Pick one of: ${[...OSV_ECOSYSTEMS].join(', ')}.`,\n        );\n    }\n    if (!OSV_ECOSYSTEMS.has(s)) {\n        throw new ArgumentError(\n            `osv --ecosystem \"${value}\" is not a recognised OSV ecosystem`,\n            `Pick one of: ${[...OSV_ECOSYSTEMS].join(', ')}.`,\n        );\n    }\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`osv ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`osv ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nasync function readJson(resp, label) {\n    let body;\n    try {\n        body = await resp.json();\n    }\n    catch (err) {\n        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);\n    }\n    return body;\n}\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/osv/utils.js#L60-L96","documentation":"requireBoundedInt coerces its input to a number and requires a positive integer for bounded numeric options like --limit; the default is used when the value is null/undefined. Non-integer or non-positive inputs throw this ArgumentError.","triggerScenarios":"Passing --limit 0, a negative number, a float like 2.5, or a non-numeric string such as 'ten' or '10abc' (Number() yields NaN).","commonSituations":"Typo in a numeric flag; hand-editing a config with 0 or -1 meaning 'unlimited'; a script passing an unparsed string; locale-formatted numbers with commas.","solutions":["Pass a positive integer, e.g. --limit 25.","Remove the flag to use the built-in default value.","Parse/validate numbers in scripts before passing them (parseInt, Number.isInteger).","If you intended 'no cap', check the command's maxValue semantics — 0 is not valid."],"exampleFix":"// before\nosvQuery({ limit: process.env.LIMIT }); // \"10abc\"\n// after\nosvQuery({ limit: Math.min(parseInt(process.env.LIMIT, 10) || 25, 1000) });","handlingStrategy":"validation","validationCode":"const n = typeof raw === 'number' ? raw : Number(raw);\nif (!Number.isInteger(n) || n <= 0) {\n  throw new Error(`--limit must be a positive integer, got: ${raw}`);\n}","typeGuard":"const isPositiveInt = (v) =>\n  (typeof v === 'number' || typeof v === 'string') && Number.isInteger(Number(v)) && Number(v) > 0;","tryCatchPattern":"try {\n  const result = await osvQuery({ limit });\n} catch (e) {\n  if (e instanceof ArgumentError && /must be a positive integer/.test(e.message)) {\n    console.error('Use a positive whole number for --limit, e.g. --limit 25');\n    return;\n  }\n  throw e;\n}","preventionTips":["Parse numeric flags with parseInt/Number before passing them on.","Never use 0 or -1 to mean 'unlimited'; omit the flag for defaults.","Sanitize env-sourced numbers (strip commas/whitespace).","Add a shell pre-check: case \"$LIMIT\" in ''|*[!0-9]*) error;; esac."],"tags":["argument-validation","numeric-validation","osv"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}