{"record":{"id":"3fe1f580c57eb774","repo":"jackwener/OpenCLI","slug":"lichess-label-must-be-maxvalue","errorCode":null,"errorMessage":"lichess ${label} must be <= ${maxValue}","messagePattern":"lichess (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/lichess/utils.js","lineNumber":53,"sourceCode":"    const raw = String(value ?? '').trim();\n    if (!raw) throw new ArgumentError('lichess perf is required (e.g. \"blitz\", \"bullet\", \"rapid\")');\n    if (!LICHESS_PERFS.has(raw)) {\n        throw new ArgumentError(\n            `lichess perf \"${value}\" is not recognised`,\n            `Allowed values: ${[...LICHESS_PERFS].join(', ')}.`,\n        );\n    }\n    return raw;\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(`lichess ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`lichess ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport async function lichessFetch(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 lichess.org is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `Lichess returned 404 for ${url}.`);\n    }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/lichess/utils.js#L35-L71","documentation":"This ArgumentError is thrown by `requireBoundedInt` when the value is a positive integer but exceeds `maxValue` for the given label. It caps how large a count the CLI will request, protecting both the user and the Lichess API.","triggerScenarios":"Calling `limit()` (via `requireBoundedInt`) with a value above the command's configured maximum, e.g. `--limit 1000` when maxValue is smaller.","commonSituations":"Assuming unbounded limits; copying limits from another tool with a higher cap; wanting 'everything' and passing a huge number; misremembering the cap for a specific subcommand.","solutions":["Lower the limit to at most the maxValue stated in the error message","Omit the limit to use the command's defaultValue","Check the specific command's docs for its cap (maxValue differs per label)","If you need more data, paginate with multiple calls at the allowed limit"],"exampleFix":"// before\nawait limit('drnik', 500); // throws if maxValue is e.g. 100\n// after\nawait limit('drnik', Math.min(Number(raw) || 20, 100));","handlingStrategy":"validation","validationCode":"function clampLimit(v, max = 100, fallback = 10) {\n  if (v == null) return fallback;\n  const n = Number(v);\n  if (!Number.isInteger(n) || n < 1) throw new TypeError('limit must be a positive integer');\n  if (n > max) throw new RangeError(`limit must be <= ${max}`);\n  return n;\n}\nawait limit(userArg, clampLimit(rawLimit, 100));","typeGuard":"function isWithinBounds(v, max) {\n  return Number.isInteger(v) && v > 0 && v <= max;\n}","tryCatchPattern":"try {\n  await limit(userArg, rawLimit);\n} catch (e) {\n  if (e instanceof ArgumentError && /must be <=/.test(e.message)) {\n    const max = Number(e.message.match(/<= (\\d+)/)?.[1] ?? 'N/A');\n    console.error(`Limit too high; retry with --limit ${max} or less.`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Check the command's documented max before passing large values","Clamp user input to the known cap in your wrapper","Omit the limit entirely to use the safe default","Paginate multiple capped calls instead of one huge request"],"tags":["lichess","argument-validation","out-of-range","limit"],"backgroundTag":"value-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}