{"record":{"id":"c42660d22eaae616","repo":"jackwener/OpenCLI","slug":"bilibili-label-api-requires-login-or-permission","errorCode":null,"errorMessage":"Bilibili ${label} API requires login or permission: ${message} (${payload.code})","messagePattern":"Bilibili (.+?) API requires login or permission: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":43,"sourceCode":"function 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\nfunction requireReplies(data, label) {\n    if (!data || typeof data !== 'object' || Array.isArray(data)) {\n        throw new CommandExecutionError(`Bilibili ${label} API returned malformed data`);\n    }\n    if (!Object.hasOwn(data, 'replies')) {\n        throw new CommandExecutionError(`Bilibili ${label} API did not return replies`);\n    }\n    if (data.replies === null) {\n        return [];\n    }\n    if (!Array.isArray(data.replies)) {\n        throw new CommandExecutionError(`Bilibili ${label} API returned malformed replies`);","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L25-L61","documentation":"AuthRequiredError thrown by requireOkPayload when the Bilibili API responds with code !== 0 that looks auth-related (code -101 or -403, or a message matching login/account/permission keywords such as 登录/账号/权限). The CLI runs with a cookie session (Strategy.COOKIE), so this means your bilibili.com session is missing, expired, or lacks permission.","triggerScenarios":"Calling `bilibili comments <bvid>` (or with --parent/--top) while logged out, with an expired cookie, or on a video whose comments require login/permission; API returns {-101: '账号未登录'} or {-403: '权限不足'} (or message contains 账号/权限/forbidden).","commonSituations":"Cookie expired after inactivity; running on a headless/CI browser with no login; comments restricted for the video or region; account flagged by risk control.","solutions":["Log in to bilibili.com in the browser session used by the CLI and refresh the cookie","Re-run the command after re-authenticating","Verify the video's comments are publicly accessible; try another video to confirm it's auth-related"],"exampleFix":"// before\nbilibili comments BV1WtAGzYEBm  // -> AuthRequiredError (-101 账号未登录)\n// after\n// 1) open bilibili.com in the CLI's browser profile and log in\n// 2) retry\nbilibili comments BV1WtAGzYEBm","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"function isAuthLike(code, msg) { return code === -101 || code === -403 || /登录|账号|权限|forbidden|permission|login/i.test(String(msg ?? '')); }","tryCatchPattern":"try { const rows = await run(['bilibili','comments',bvid]); } catch (e) { if (/requires login or permission/.test(e.message)) { console.error('Bilibili login required — re-authenticate the cookie session'); process.exitCode = 3; } else throw e; }","preventionTips":["Log in to bilibili.com in the CLI's browser profile before running batch jobs","Refresh cookies periodically in long-running scripts","Detect code -101/-403 early and re-auth rather than retrying blindly"],"tags":["auth","cookies","session-expired"],"backgroundTag":"auth-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}