jackwener/OpenCLI · error · ArgumentError

npm ${label} must be <= ${maxValue}

Error message

npm ${label} must be <= ${maxValue}

What it means

requireBoundedInt also enforces an upper bound: after passing positivity, values greater than maxValue throw ArgumentError `npm ${label} must be <= ${maxValue}` (e.g. `npm limit must be <= 250` for search). This keeps requests within what the npm search API's size parameter accepts.

Source

Thrown at clis/npm/utils.js:40

        throw new ArgumentError(`npm package name "${value}" is too long (max 214 chars)`);
    }
    if (!PKG_NAME.test(s)) {
        throw new ArgumentError(
            `npm package name "${value}" is not a valid registry name`,
            'Names are 1–214 chars of lowercase a-z / 0-9 / "-._" (scoped form: "@scope/name").',
        );
    }
    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(`npm ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`npm ${label} must be <= ${maxValue}`);
    }
    return n;
}

export async function npmFetch(url, label) {
    let resp;
    try {
        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
    }
    catch (err) {
        throw new CommandExecutionError(
            `${label} request failed: ${err?.message ?? err}`,
            'Check that registry.npmjs.org / api.npmjs.org are reachable from this network.',
        );
    }
    if (resp.status === 404) {
        throw new EmptyResultError(label, `npm registry returned 404 for ${url}.`);
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use limit <= 250; for more results, paginate by refining the query or issuing successive searches.
  2. Omit the limit argument to use the default of 20.
  3. Clamp input before calling: Math.min(value, 250).
  4. Catch ArgumentError and surface the allowed maximum to the user.

Example fix

// before
await npmSearch({ query: 'react', limit: 1000 }); // ArgumentError: must be <= 250
// after
const requested = Number(process.env.LIMIT ?? 20);
await npmSearch({ query: 'react', limit: Math.min(Math.max(requested, 1), 250) });
Defensive patterns

Strategy: validation

Validate before calling

function clampLimit(v, dflt = 20, max = 250) {
  if (v == null) return dflt;
  const n = typeof v === 'number' ? v : Number(v);
  if (!Number.isInteger(n) || n <= 0) return dflt;
  return Math.min(n, max);
}
const limit = clampLimit(args.limit);

Type guard

function isWithinLimit(v, max) {
  return typeof v === 'number' && Number.isInteger(v) && v > 0 && v <= max;
}

Try / catch

try {
  return await npmSearch({ query, limit });
} catch (e) {
  if (e.name === 'ArgumentError' && /must be <=/.test(e.message)) {
    return await npmSearch({ query, limit: 250 }); // clamp to the API maximum
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling npm search with limit above 250 (search.js calls requireBoundedInt(args.limit, 20, 250)) — e.g. `--limit 1000` or programmatic limit=500.

Common situations: Trying to fetch 'all results' with a huge limit; assuming the max is unlimited; copying a limit from another tool with different bounds; batch scripts requesting page sizes the API won't serve.

Related errors


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