{"record":{"id":"dd3d4e8f428c80b8","repo":"jackwener/OpenCLI","slug":"bilibili-label-api-failed-message-payloa","errorCode":null,"errorMessage":"Bilibili ${label} API failed: ${message} (${payload.code})","messagePattern":"Bilibili (.+?) API failed: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":45,"sourceCode":"        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`);\n    }\n    return data.replies;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L27-L63","documentation":"CommandExecutionError thrown by requireOkPayload when the Bilibili API returns a non-zero code that is not auth-like. The code is the Bilibili API's own error code (e.g. -400 request error, -404 not found, 12061 comment closed) and the message is the API's Chinese-language error text.","triggerScenarios":"The view/reply API responds {code: -400, message: '请求错误'} or similar non-zero, non-auth code — e.g. invalid oid/type params, deleted video, comments disabled, or wrong rpid passed as --parent.","commonSituations":"Deleted or private video; comment section closed by uploader; invalid --parent rpid that no longer exists; Bilibili server-side transient error (code -509 or similar rate-limit codes).","solutions":["Read the code/message in the error to identify the API-level cause","Verify the bvid resolves to an existing video and comments are enabled","If --parent was used, confirm the rpid exists and belongs to this video","Retry later if the code indicates a transient/rate-limit condition"],"exampleFix":"// before\nbilibili comments BV1Deleted000 --parent 123  // code -404\n// after\nbilibili comments BV1WtAGzYEBm  // valid video, top-level comments","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"function isBiliApiError(x) { return !!x && typeof x === 'object' && 'code' in x && x.code !== 0; }","tryCatchPattern":"try { const rows = await run(['bilibili','comments',bvid]); } catch (e) { const m = /API failed: .* \\((-?\\d+)\\)/.exec(e.message); if (m) { const code = Number(m[1]); if (code === -509 || code === -412) return retryWithBackoff(fn); if (code === -404) console.error('video or rpid not found'); } throw e; }","preventionTips":["Validate the bvid/rpid inputs before calling","Handle rate-limit codes with backoff, not tight retries","Check the video exists and comments are enabled before processing"],"tags":["network","api-response","upstream-error"],"backgroundTag":"api-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}