jackwener/OpenCLI · error · ArgumentError

osv ${label} must be a positive integer

Error message

osv ${label} must be a positive integer

What it means

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.

Source

Thrown at clis/osv/utils.js:78

        throw new ArgumentError(
            'osv --ecosystem is required when querying by package',
            `Pick one of: ${[...OSV_ECOSYSTEMS].join(', ')}.`,
        );
    }
    if (!OSV_ECOSYSTEMS.has(s)) {
        throw new ArgumentError(
            `osv --ecosystem "${value}" is not a recognised OSV ecosystem`,
            `Pick one of: ${[...OSV_ECOSYSTEMS].join(', ')}.`,
        );
    }
    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(`osv ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`osv ${label} must be <= ${maxValue}`);
    }
    return n;
}

async function readJson(resp, label) {
    let body;
    try {
        body = await resp.json();
    }
    catch (err) {
        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);
    }
    return body;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. --limit 25.
  2. Remove the flag to use the built-in default value.
  3. Parse/validate numbers in scripts before passing them (parseInt, Number.isInteger).
  4. If you intended 'no cap', check the command's maxValue semantics — 0 is not valid.

Example fix

// before
osvQuery({ limit: process.env.LIMIT }); // "10abc"
// after
osvQuery({ limit: Math.min(parseInt(process.env.LIMIT, 10) || 25, 1000) });
Defensive patterns

Strategy: validation

Validate before calling

const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isInteger(n) || n <= 0) {
  throw new Error(`--limit must be a positive integer, got: ${raw}`);
}

Type guard

const isPositiveInt = (v) =>
  (typeof v === 'number' || typeof v === 'string') && Number.isInteger(Number(v)) && Number(v) > 0;

Try / catch

try {
  const result = await osvQuery({ limit });
} catch (e) {
  if (e instanceof ArgumentError && /must be a positive integer/.test(e.message)) {
    console.error('Use a positive whole number for --limit, e.g. --limit 25');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing --limit 0, a negative number, a float like 2.5, or a non-numeric string such as 'ten' or '10abc' (Number() yields NaN).

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/041973d0c06e40ae. Report an issue: GitHub.