{"record":{"id":"2f4566d98b2b4cc4","repo":"jackwener/OpenCLI","slug":"pubmed-label-must-be-maxvalue","errorCode":null,"errorMessage":"pubmed ${label} must be <= ${maxValue}","messagePattern":"pubmed (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/pubmed/utils.js","lineNumber":37,"sourceCode":"    const pmid = requireText(value, label);\n    if (!/^\\d+$/.test(pmid)) {\n        throw new ArgumentError(`pubmed ${label} must be a numeric PMID`, 'Example: 37780221');\n    }\n    return pmid;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const text = String(raw).trim();\n    if (!/^\\d+$/.test(text)) {\n        throw new ArgumentError(`pubmed ${label} must be a positive integer`);\n    }\n    const n = Number(text);\n    if (!Number.isSafeInteger(n) || n < 1) {\n        throw new ArgumentError(`pubmed ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`pubmed ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireYear(value, label) {\n    if (value === undefined || value === null || value === '') {\n        return undefined;\n    }\n    const year = requireBoundedInt(value, 1900, 3000, label);\n    if (year < 1800) {\n        throw new ArgumentError(`pubmed ${label} must be >= 1800`);\n    }\n    return year;\n}\n\nexport function requireChoice(value, choices, label, defaultValue) {\n    const text = String(value ?? defaultValue).trim();\n    if (!choices.includes(text)) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pubmed/utils.js#L19-L55","documentation":"requireBoundedInt's final check: the validated integer is compared to the caller-provided maxValue ceiling (e.g. max results per request). Exceeding it throws ArgumentError 'pubmed <label> must be <= <maxValue>'.","triggerScenarios":"Requesting more results than the command allows, e.g. `--limit 100000` when the cap is lower.","commonSituations":"Trying to fetch an entire large result set in one call, forwarding raw user-supplied page sizes, misremembering the documented cap.","solutions":["Lower the limit to the value stated in the error message","Paginate: issue multiple narrower searches instead of one huge limit","Check the command's --help for the exact maximum"],"exampleFix":"// before\n--limit 100000\n// after\n--limit 100  // paginate for more","handlingStrategy":"validation","validationCode":"const MAX = 100; // per command docs\nif (Number(limit) > MAX) {\n  console.warn(`--limit ${limit} exceeds max ${MAX}; clamping`);\n  limit = MAX;\n}","typeGuard":"function isWithinMax(v, max) {\n  const n = Number(v);\n  return Number.isSafeInteger(n) && n >= 1 && n <= max;\n}","tryCatchPattern":"try {\n  await pubmedSearch(query, { limit });\n} catch (err) {\n  const m = /must be <= (\\d+)/.exec(err.message ?? '');\n  if (err instanceof ArgumentError && m) {\n    await pubmedSearch(query, { limit: Number(m[1]) }); // retry at max\n  } else { throw err; }\n}","preventionTips":["Read the error message — it states the exact maximum","Paginate instead of raising the limit","Clamp user-supplied page sizes against the documented cap before invoking"],"tags":["validation","argument-error","limit-exceeded","cli-options"],"backgroundTag":"parameter-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}