jackwener/OpenCLI · error · ArgumentError
maven ${label} must be a positive integer
Error message
maven ${label} must be a positive integer What it means
`requireBoundedInt` validates numeric arguments (defaulting to `defaultValue` when omitted) and throws ArgumentError with `maven ${label} must be a positive integer` when the value is not an integer or is <= 0. For the `limit` argument this means you passed something like 0, -5, NaN, a non-numeric string, or a fractional number as the result limit.
Source
Thrown at clis/maven/utils.js:26
export const MAVEN_BASE = 'https://search.maven.org/solrsearch/select';
export const MAVEN_REPO_BASE = 'https://repo1.maven.org/maven2';
const UA = 'opencli-maven-adapter (+https://github.com/jackwener/opencli)';
// Maven groupId / artifactId tokens — Java-package-ish (letters / digits /
// `_-.`), 1-200 chars; reverse-DNS dots are allowed in groupId.
const COORD_TOKEN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`maven ${label} cannot be empty`);
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(`maven ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`maven ${label} must be <= ${maxValue}`);
}
return n;
}
/**
* Parse a Maven coordinate `groupId:artifactId[:version]` into segments.
* groupId / artifactId are required; version is optional.
*/
export function requireCoord(value) {
const raw = String(value ?? '').trim();
if (!raw) {
throw new ArgumentError('maven coordinate is required (e.g. "com.fasterxml.jackson.core:jackson-databind")');
}
const parts = raw.split(':');
if (parts.length < 2 || parts.length > 3) {View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer for the argument (e.g. limit: 20) or omit it to use the default (30)
- Coerce and validate user input before the call: Number.isInteger(Number(value)) && Number(value) > 0
- Check whether a falsy value (0, null) is accidentally overriding the library's default via `value ?? defaultValue` — null/undefined are fine, 0 is not
- Note the upper bound too: the value must also be <= 200 for limit
Example fix
// before
await mavenSearch({ query: 'jackson', limit: 0 });
// after
await mavenSearch({ query: 'jackson', limit: Math.min(200, Math.max(1, parseInt(userLimit, 10) || 30)) }); Defensive patterns
Strategy: validation
Validate before calling
function parseLimit(v, dflt = 30, max = 200) {
if (v == null) return dflt;
const n = typeof v === 'number' ? v : Number(v);
if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');
return n;
} Type guard
function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; } Try / catch
try {
const docs = await mavenSearch({ query, limit });
} catch (err) {
if (err instanceof ArgumentError && /positive integer/.test(err.message)) {
console.error('limit must be a positive integer, e.g. --limit 30');
return;
}
throw err;
} Prevention
- Omit the limit argument to use the default (30) unless you need otherwise
- Coerce CLI strings with parseInt and validate with Number.isInteger
- Guard against 0 and null overriding defaults — null/undefined fall back, 0 throws
- Sanitize user input before passing numeric options
When it happens
Trigger: Calling an operation with `limit: 0`, `limit: -1`, `limit: 'ten'`, `limit: 2.5`, or `limit: NaN` — anything where Number coercion does not produce a positive integer. Omitting limit is fine (defaults to 30).
Common situations: A CLI flag parsed as string ('--limit 0' becomes the string '0', still 0 -> throws); a config value of null explicitly overriding the default; user input not sanitized; JS NaN from a failed parseInt; passing a boolean or object by mistake.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- maven ${label} cannot be empty
- maven ${label} must be <= ${maxValue}
- maven coordinate is required (e.g. "com.fasterxml.jackson.co
- maven coordinate "${value}" must be "groupId:artifactId" or
- maven coordinate "${value}" is missing groupId or artifactId
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7f2ad460bf247615.
Report an issue: GitHub.