jackwener/OpenCLI · error · ArgumentError
goproxy ${label} must be a positive integer
Error message
goproxy ${label} must be a positive integer What it means
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.
Source
Thrown at clis/goproxy/utils.js:52
}
export function requireVersionTag(value) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError('goproxy --version cannot be empty');
if (!VERSION_TAG.test(s)) {
throw new ArgumentError(
`goproxy --version "${value}" is not a valid Go semver tag`,
'Use the GOPROXY canonical form like "v1.2.3" or "v0.0.0-20240101010101-abcdef012345".',
);
}
return s;
}
export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
const raw = value ?? defaultValue;
const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError(`goproxy ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`goproxy ${label} must be <= ${maxValue}`);
}
return n;
}
async function rawFetch(url, label) {
let resp;
try {
resp = await fetch(url, { headers: { 'user-agent': UA } });
}
catch (err) {
throw new CommandExecutionError(
`${label} request failed: ${err?.message ?? err}`,
'Check that proxy.golang.org is reachable from this network.',
);
}View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
limit(process.env.LIMIT); // LIMIT='' → Number('') = 0 → throws
// after
const n = process.env.LIMIT ? Number(process.env.LIMIT) : undefined;
limit(n); // undefined → built-in default applies Defensive patterns
Strategy: validation
Validate before calling
function toPositiveInt(v) {
const n = v == null ? undefined : Number(v);
if (n !== undefined && (!Number.isInteger(n) || n <= 0)) {
throw new Error(`limit must be a positive integer, got: ${v}`);
}
return n;
}
const parsed = toPositiveInt(rawInput); Type guard
const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v > 0;
Try / catch
try {
const n = limit(rawInput);
} catch (err) {
if (err instanceof ArgumentError && /must be a positive integer/.test(err.message)) {
console.error(`--limit must be a whole number > 0 (got '${rawInput}')`);
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- goproxy module path is required (e.g. "github.com/gin-gonic/
- goproxy module path "${value}" is not a recognised Go module
- goproxy --version cannot be empty
- goproxy --version "${value}" is not a valid Go semver tag
- goproxy ${label} must be <= ${maxValue}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/96559fd2e46dc169.
Report an issue: GitHub.