{"record":{"id":"96559fd2e46dc169","repo":"jackwener/OpenCLI","slug":"goproxy-label-must-be-a-positive-integer","errorCode":null,"errorMessage":"goproxy ${label} must be a positive integer","messagePattern":"goproxy (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/goproxy/utils.js","lineNumber":52,"sourceCode":"}\n\nexport function requireVersionTag(value) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError('goproxy --version cannot be empty');\n    if (!VERSION_TAG.test(s)) {\n        throw new ArgumentError(\n            `goproxy --version \"${value}\" is not a valid Go semver tag`,\n            'Use the GOPROXY canonical form like \"v1.2.3\" or \"v0.0.0-20240101010101-abcdef012345\".',\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(`goproxy ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`goproxy ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nasync function rawFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that proxy.golang.org is reachable from this network.',\n        );\n    }","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/goproxy/utils.js#L34-L70","documentation":"Thrown by requireBoundedInt at clis/goproxy/utils.js:52 when the resolved value (user value or the default) is not an integer greater than zero. It guards numeric options like page size/limit before they are interpolated into GOPROXY query URLs.","triggerScenarios":"Passing --limit abc, --limit 0, --limit -5, a float like 2.5, or an empty string that is not null (so the ?? default is bypassed and Number('') → 0 fails the check); also NaN from non-numeric strings.","commonSituations":"Typing a non-numeric CLI value; shell variable empty but quoted so it is '' rather than unset; copy-pasting '1,000' with a thousands separator; script passing null vs '' confusion with ?? semantics.","solutions":["Pass a positive whole number, e.g. --limit 20.","Ensure empty values are actually undefined/null (so the built-in default applies) instead of '' — `Number('')` is 0 and fails.","Strip formatting characters ('1,000' → '1000') before calling the API.","In scripts, validate with Number.isInteger(+value) && +value > 0 before invoking."],"exampleFix":"// before\nlimit(process.env.LIMIT);        // LIMIT='' → Number('') = 0 → throws\n// after\nconst n = process.env.LIMIT ? Number(process.env.LIMIT) : undefined;\nlimit(n);                        // undefined → built-in default applies","handlingStrategy":"validation","validationCode":"function toPositiveInt(v) {\n  const n = v == null ? undefined : Number(v);\n  if (n !== undefined && (!Number.isInteger(n) || n <= 0)) {\n    throw new Error(`limit must be a positive integer, got: ${v}`);\n  }\n  return n;\n}\nconst parsed = toPositiveInt(rawInput);","typeGuard":"const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v > 0;","tryCatchPattern":"try {\n  const n = limit(rawInput);\n} catch (err) {\n  if (err instanceof ArgumentError && /must be a positive integer/.test(err.message)) {\n    console.error(`--limit must be a whole number > 0 (got '${rawInput}')`);\n  } else throw err;\n}","preventionTips":["Parse numeric flags with a dedicated parser (e.g. parseInt with NaN check) at CLI boundary.","Coerce ''/whitespace-only inputs to undefined so library defaults apply.","Reject floats and formatted numbers ('1,000') before passing them through."],"tags":["argument-error","input-validation","goproxy","numeric-parsing"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}