{"record":{"id":"a64a74c704e1bd87","repo":"jackwener/OpenCLI","slug":"label-must-be-maxvalue-a64a74","errorCode":null,"errorMessage":"${label} must be <= ${maxValue}","messagePattern":"(.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hltv/utils.js","lineNumber":67,"sourceCode":"  cache: 'de_cache',\n  cobblestone: 'de_cobblestone',\n  season: 'de_season',\n  train: 'de_train',\n  tuscan: 'de_tuscan',\n  vertigo: 'de_vertigo',\n};\n\nexport const VERSIONS = {\n  both: null,\n  cs2: 'CS2',\n  csgo: 'CSGO',\n};\n\nexport function normalizeLimit(value, defaultValue, maxValue, label = 'limit') {\n  const raw = value ?? defaultValue;\n  const n = Number(raw);\n  if (!Number.isInteger(n) || n <= 0) throw new ArgumentError(`${label} must be a positive integer`);\n  if (n > maxValue) throw new ArgumentError(`${label} must be <= ${maxValue}`);\n  return n;\n}\n\nexport function normalizeOffset(value, defaultValue = 0) {\n  const raw = value ?? defaultValue;\n  const n = Number(raw);\n  if (!Number.isInteger(n) || n < 0) throw new ArgumentError('offset must be a non-negative integer');\n  if (n % 100 !== 0) throw new ArgumentError('offset must be a multiple of 100');\n  return n;\n}\n\nexport function normalizeChoice(value, defaultValue, choices, label) {\n  const raw = String(value ?? defaultValue);\n  if (!Object.prototype.hasOwnProperty.call(choices, raw)) {\n    throw new ArgumentError(`${label} must be one of: ${Object.keys(choices).join(', ')}`);\n  }\n  return raw;\n}","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hltv/utils.js#L49-L85","documentation":"normalizeLimit validates a user-supplied limit/pageSize option before building an HLTV API request. It throws ArgumentError when the value is not a positive integer, and this specific error when the value exceeds the command's configured maxValue cap. The cap exists because HLTV's endpoints reject or truncate requests with excessively large limits.","triggerScenarios":"Passing a limit larger than the command's max (e.g. --limit 500 where max is 100), or programmatically calling limit/normalizeLimit(value, default, maxValue) with maxValue exceeded.","commonSituations":"Users copy a limit from another API's docs assuming unlimited paging; scripts that guess page sizes; misremembering the CLI's documented cap for a specific subcommand.","solutions":["Lower the limit to the command's documented maximum (check the option help for maxValue)","If more results are needed, page through with offset increments instead of one large limit","Ensure the value passed is a number, not a string like '500' that may fail the integer check first"],"exampleFix":"// before\nhltv top20 --limit 1000\n// after\nhltv top20 --limit 100  # or page: --limit 100 --offset 100","handlingStrategy":"validation","validationCode":"function validateLimit(v, max) { const n = Number(v); return Number.isInteger(n) && n > 0 && n <= max; }\nif (!validateLimit(opts.limit, 100)) throw new Error(`limit must be a positive integer <= 100`);","typeGuard":"const isLimit = (v, max) => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) <= max;","tryCatchPattern":"try {\n  await hltv.top20({ limit });\n} catch (e) {\n  if (e.name === 'ArgumentError') { console.error(`Bad --limit: ${e.message}`); process.exitCode = 2; }\n  else throw e;\n}","preventionTips":["Clamp the limit before calling: limit = Math.min(Number(limit) || 100, max)","Page with offset instead of raising the limit","Read the command's --help to learn the per-command maximum"],"tags":["cli","validation","argument-error","hltv"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}