{"record":{"id":"8d29ad8f58e3b2b5","repo":"jackwener/OpenCLI","slug":"bilibili-comments-limit-must-be-an-integer-between","errorCode":null,"errorMessage":"bilibili comments limit must be an integer between 1 and ${MAX_LIMIT}","messagePattern":"bilibili comments limit must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":20,"sourceCode":" * Bilibili comments — fetches comments via the official API.\n * Top-level and pinned comments come from /x/v2/reply/main (WBI-signed); with\n * --parent, replies nested under a given comment come from /x/v2/reply/reply.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { apiGet, resolveBvid } from './utils.js';\n\nconst MAX_LIMIT = 50;\n\nfunction isAuthLikeBilibiliError(code, message) {\n    return code === -101 || code === -403 || /登录|账号|权限|forbidden|permission|login/i.test(String(message ?? ''));\n}\n\nfunction parseLimit(value) {\n    const raw = value == null ? 20 : value;\n    const limit = Number(raw);\n    if (!Number.isInteger(limit) || limit <= 0 || limit > MAX_LIMIT) {\n        throw new ArgumentError(`bilibili comments limit must be an integer between 1 and ${MAX_LIMIT}`);\n    }\n    return limit;\n}\n\nfunction parseParent(value) {\n    if (value == null) {\n        return null;\n    }\n    const parent = Number(value);\n    if (!Number.isInteger(parent) || parent <= 0) {\n        throw new ArgumentError('bilibili comments parent must be a positive integer rpid');\n    }\n    return parent;\n}\n\nfunction requireOkPayload(payload, label) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload) || !Object.hasOwn(payload, 'code')) {\n        throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L2-L38","documentation":"ArgumentError thrown by parseLimit in clis/bilibili/comments.js when the --limit option fails validation. The value must be an integer between 1 and MAX_LIMIT (50); the default is 20 when omitted. Values like 0, negative numbers, floats, or numbers above 50 are rejected before any API call is made.","triggerScenarios":"Calling `bilibili comments <bvid> --limit 0`, `--limit -5`, `--limit 51`, `--limit 12.5`, or passing a non-numeric string (Number() coerces it to NaN) to the limit kwarg.","commonSituations":"Scripts parameterizing the limit from user input or env vars with invalid values; assuming the API allows more than 50 comments per page; passing a string like '20 ' or 'all' that fails Number() coercion.","solutions":["Set --limit to an integer between 1 and 50, or omit it to use the default of 20","If more than 50 comments are needed, fetch multiple pages instead of raising the limit","Sanitize the value before passing: Math.trunc(Number(value)) and clamp to [1, 50]"],"exampleFix":"// before\nbilibili comments BV1WtAGzYEBm --limit 100\n// after\nbilibili comments BV1WtAGzYEBm --limit 50","handlingStrategy":"validation","validationCode":"function isValidLimit(v) { const n = Number(v); return Number.isInteger(n) && n >= 1 && n <= 50; }\nif (!isValidLimit(limit)) limit = 20;","typeGuard":"function isFiniteInt(v) { return typeof v === 'number' && Number.isInteger(v); }","tryCatchPattern":"try { const rows = await run(['bilibili','comments',bvid,'--limit',String(limit)]); } catch (e) { if (/limit must be an integer/.test(e.message)) { console.warn('invalid limit, using default 20'); } else throw e; }","preventionTips":["Clamp user-supplied limits: Math.min(50, Math.max(1, Math.trunc(Number(v))))","Never pass raw env-var/script strings directly as --limit","Remember the hard cap is 50 per page; paginate instead"],"tags":["validation","argument-error","cli-options"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}