{"record":{"id":"438964fbf79b49b3","repo":"jackwener/OpenCLI","slug":"juejin-label-must-be-maxvalue","errorCode":null,"errorMessage":"juejin ${label} must be <= ${maxValue}","messagePattern":"juejin (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/juejin/utils.js","lineNumber":50,"sourceCode":"}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    let n;\n    if (typeof raw === 'number') {\n        n = raw;\n    }\n    else if (typeof raw === 'string' && /^[1-9]\\d*$/.test(raw)) {\n        n = Number(raw);\n    }\n    else {\n        throw new ArgumentError(`juejin ${label} must be a positive decimal integer`);\n    }\n    if (!Number.isSafeInteger(n) || n <= 0) {\n        throw new ArgumentError(`juejin ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`juejin ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireCursor(value) {\n    const raw = value ?? '0';\n    if (typeof raw === 'number') {\n        if (Number.isSafeInteger(raw) && raw >= 0) return String(raw);\n        throw new ArgumentError('juejin cursor must be a non-negative decimal integer');\n    }\n    if (typeof raw === 'string' && /^(0|[1-9]\\d*)$/.test(raw)) {\n        return raw;\n    }\n    throw new ArgumentError('juejin cursor must be a non-negative decimal integer');\n}\n\n/** Resolve a `--category` arg to the underlying numeric category id. */\nexport function resolveCategory(value) {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/juejin/utils.js#L32-L68","documentation":"requireBoundedInt enforces an upper bound (maxValue) on limit-like arguments. When the parsed positive integer exceeds the command's configured maximum, this ArgumentError is thrown with the exact allowed maximum in the message, preventing oversized requests that the API would reject or that would waste resources.","triggerScenarios":"Passing a limit above the command's max, e.g. --limit 1000 where the recommend command's maxValue is 50, or --limit 100 on an endpoint capped at 20.","commonSituations":"Reusing a limit tuned for a different CLI/API with a higher cap; config files shared across commands with different maxima; scripting pagination with pagesize set larger than the server allows.","solutions":["Lower the limit to the value named in the error message (e.g. --limit 50).","To fetch more items, paginate: loop with --limit <max> and follow next_cursor instead of one huge request.","Clamp in your wrapper script: n = Math.min(maxAllowed, requested).","Check the command's --help for its documented maximum."],"exampleFix":"// before\ncli({ limit: 1000 }); // exceeds max\n// after\nfor (let cursor = '0'; cursor !== ''; ) {\n  const page = cli({ limit: 50, cursor });\n  cursor = page.next_cursor;\n}","handlingStrategy":"validation","validationCode":"const MAX = 50; // match the command's documented max\nfunction safeLimit(n){ return Math.min(MAX, Math.max(1, Math.floor(Number(n) || 1))); }\n// cli({ limit: safeLimit(requested) })","typeGuard":"function isWithinMax(v, max){ return typeof v === 'number' && Number.isSafeInteger(v) && v > 0 && v <= max; }","tryCatchPattern":"try {\n  cli({ limit });\n} catch (e) {\n  const m = /must be <= (\\d+)/.exec(e.message);\n  if (m) cli({ limit: Number(m[1]) }); // retry at the exact allowed max\n  else throw e;\n}","preventionTips":["Read --help for each command's maximum; maxima differ per endpoint.","Paginate with next_cursor instead of raising the limit beyond the cap.","Centralize the max in one constant shared by all your wrappers."],"tags":["argument-validation","cli","limit","pagination"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}