{"record":{"id":"f42ae241496dab42","repo":"jackwener/OpenCLI","slug":"npm-label-must-be-maxvalue","errorCode":null,"errorMessage":"npm ${label} must be <= ${maxValue}","messagePattern":"npm (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/npm/utils.js","lineNumber":40,"sourceCode":"        throw new ArgumentError(`npm package name \"${value}\" is too long (max 214 chars)`);\n    }\n    if (!PKG_NAME.test(s)) {\n        throw new ArgumentError(\n            `npm package name \"${value}\" is not a valid registry name`,\n            'Names are 1–214 chars of lowercase a-z / 0-9 / \"-._\" (scoped form: \"@scope/name\").',\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(`npm ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`npm ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport async function npmFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that registry.npmjs.org / api.npmjs.org are reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `npm registry returned 404 for ${url}.`);\n    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/npm/utils.js#L22-L58","documentation":"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.","triggerScenarios":"Calling npm search with limit above 250 (search.js calls requireBoundedInt(args.limit, 20, 250)) — e.g. `--limit 1000` or programmatic limit=500.","commonSituations":"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.","solutions":["Use limit <= 250; for more results, paginate by refining the query or issuing successive searches.","Omit the limit argument to use the default of 20.","Clamp input before calling: Math.min(value, 250).","Catch ArgumentError and surface the allowed maximum to the user."],"exampleFix":"// before\nawait npmSearch({ query: 'react', limit: 1000 }); // ArgumentError: must be <= 250\n// after\nconst requested = Number(process.env.LIMIT ?? 20);\nawait npmSearch({ query: 'react', limit: Math.min(Math.max(requested, 1), 250) });","handlingStrategy":"validation","validationCode":"function clampLimit(v, dflt = 20, max = 250) {\n  if (v == null) return dflt;\n  const n = typeof v === 'number' ? v : Number(v);\n  if (!Number.isInteger(n) || n <= 0) return dflt;\n  return Math.min(n, max);\n}\nconst limit = clampLimit(args.limit);","typeGuard":"function isWithinLimit(v, max) {\n  return typeof v === 'number' && Number.isInteger(v) && v > 0 && v <= max;\n}","tryCatchPattern":"try {\n  return await npmSearch({ query, limit });\n} catch (e) {\n  if (e.name === 'ArgumentError' && /must be <=/.test(e.message)) {\n    return await npmSearch({ query, limit: 250 }); // clamp to the API maximum\n  }\n  throw e;\n}","preventionTips":["Cap limits at 250 — the npm search API's maximum size.","For 'all results', paginate with successive searches instead of one huge limit.","Clamp with Math.min before calling.","Document the 1-250 range in your CLI help."],"tags":["validation","argument-error","npm","bounds-check","pagination"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}