{"record":{"id":"aac63a8c4d33e7d4","repo":"jackwener/OpenCLI","slug":"homebrew-label-must-be-maxvalue","errorCode":null,"errorMessage":"homebrew ${label} must be <= ${maxValue}","messagePattern":"homebrew (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/homebrew/utils.js","lineNumber":29,"sourceCode":"\n// Homebrew formula / cask tokens — letters / digits / `_-.+@` (`gcc@13`,\n// `imagemagick@6`, `c++`, `0-ad`, `php-cs-fixer`).\nconst TOKEN = /^[A-Za-z0-9][A-Za-z0-9._+@-]*$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`homebrew ${label} cannot be empty`);\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(`homebrew ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`homebrew ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireToken(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) {\n        throw new ArgumentError(`homebrew ${label} is required (e.g. \"wget\", \"gcc@13\", \"firefox\")`);\n    }\n    if (s.length > 100 || !TOKEN.test(s)) {\n        throw new ArgumentError(\n            `homebrew ${label} \"${value}\" is not a valid token`,\n            'Use letters / digits / \"_-.+@\", starting with a letter or digit (max 100 chars).',\n        );\n    }\n    return s;\n}\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/homebrew/utils.js#L11-L47","documentation":"requireBoundedInt throws ArgumentError('homebrew <label> must be <= <maxValue>') when the numeric value is a valid positive integer but exceeds the adapter's upper bound (e.g. limit > 500 for the popular command). The cap prevents abusive or nonsensical requests.","triggerScenarios":"Calling the popular/list command with --limit 1000 when the maximum is 500, or any label-specific value above its configured maxValue.","commonSituations":"Users trying to export the full analytics list in one call, or scripts hardcoding large page sizes from another API's conventions.","solutions":["Lower the value to at most the documented maximum (e.g. --limit 500)","Paginate or fetch in chunks if more items are needed","Check the command's --help for the allowed range","Pre-clamp the value with Math.min(value, max) in scripts"],"exampleFix":"// before\nawait homebrewPopular({ limit: 1000 });\n// after\nconst limit = Math.min(Number(args.limit) || 30, 500);\nawait homebrewPopular({ limit });","handlingStrategy":"validation","validationCode":"function clampLimit(raw, max = 500, def = 30) {\n  const n = Number(raw ?? def);\n  if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');\n  return Math.min(n, max);\n}","typeGuard":"function isWithinBound(v, max) {\n  return typeof v === 'number' && Number.isInteger(v) && v > 0 && v <= max;\n}","tryCatchPattern":"try {\n  await homebrewPopular({ limit });\n} catch (err) {\n  if (err instanceof ArgumentError && /must be <=/.test(err.message)) {\n    const max = Number(err.message.match(/<= (\\d+)/)?.[1] ?? 500);\n    console.error(`--limit capped at ${max}`);\n    return homebrewPopular({ limit: max });\n  }\n  throw err;\n}","preventionTips":["Clamp user-supplied limits with Math.min before calling","Document the max in your wrapper's help text","Parse the max bound from the error message for auto-correction","Paginate instead of requesting oversized result sets"],"tags":["validation","argument-error","limits"],"backgroundTag":"argument-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}