{"record":{"id":"e02271b35a140bf9","repo":"jackwener/OpenCLI","slug":"bilibili-comments-parent-must-be-a-positive-intege","errorCode":null,"errorMessage":"bilibili comments parent must be a positive integer rpid","messagePattern":"bilibili comments parent must be a positive integer rpid","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":31,"sourceCode":"    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`);\n    }\n    if (payload.code !== 0) {\n        const message = payload.message ?? 'unknown error';\n        if (isAuthLikeBilibiliError(payload.code, message)) {\n            throw new AuthRequiredError('bilibili.com', `Bilibili ${label} API requires login or permission: ${message} (${payload.code})`);\n        }\n        throw new CommandExecutionError(`Bilibili ${label} API failed: ${message} (${payload.code})`);\n    }\n    return payload.data;\n}\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L13-L49","documentation":"ArgumentError thrown by parseParent when the --parent option (a Bilibili comment rpid used to fetch nested 'floor' replies) is not a positive integer. Null/undefined is allowed (means 'no parent'), but any provided value must coerce via Number() to an integer > 0.","triggerScenarios":"Calling `bilibili comments <bvid> --parent abc`, `--parent 0`, `--parent -1`, or `--parent 12.5`; passing an rpid that was truncated or mangled (e.g. lost precision as a JS number elsewhere).","commonSituations":"Copy-pasting a partial rpid; treating rpid as a float; shell quoting issues that split the rpid; rpid sourced from JSON parsed with numbers losing precision for very large ids.","solutions":["Pass the full numeric rpid exactly as shown in the comments table (rank/rpid column)","Verify the rpid is a positive integer string before passing it","Keep rpid as a string in scripts to avoid precision loss, and only pass digits"],"exampleFix":"// before\nbilibili comments BV1WtAGzYEBm --parent 0\n// after\nbilibili comments BV1WtAGzYEBm --parent 3498271543","handlingStrategy":"validation","validationCode":"function isValidRpid(v) { return v != null && Number.isInteger(Number(v)) && Number(v) > 0; }\nif (parent != null && !isValidRpid(parent)) throw new Error('parent must be a positive integer rpid');","typeGuard":"function isPositiveInt(v) { const n = Number(v); return Number.isInteger(n) && n > 0; }","tryCatchPattern":"try { ... } catch (e) { if (/parent must be a positive integer/.test(e.message)) { console.error('bad --parent rpid: ' + parent); process.exitCode = 2; } else throw e; }","preventionTips":["Copy rpid verbatim from the comments table output","Store rpid as a string to avoid JS number precision loss on large ids","Validate with /^\\d+$/ before passing --parent"],"tags":["validation","argument-error","cli-options"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}