{"record":{"id":"cd69ea1a4038ec35","repo":"jackwener/OpenCLI","slug":"bilibili-label-api-returned-malformed-data","errorCode":null,"errorMessage":"Bilibili ${label} API returned malformed data","messagePattern":"Bilibili (.+?) API returned malformed data","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":52,"sourceCode":"}\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;\n}\n\nfunction requireTopReplies(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, 'top_replies')) {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L34-L70","documentation":"CommandExecutionError thrown by requireReplies when the `data` field inside a successful (code===0) reply API envelope is not a plain object. Bilibili's /x/v2/reply/main or /x/v2/reply/reply should return an object containing a `replies` key; anything else indicates a contract violation.","triggerScenarios":"API returns code 0 but data is null, a string, an array, or missing — e.g. WBI signature accepted but response shape changed, or risk-control returns an empty success.","commonSituations":"Bilibili silently changing the reply API response shape; regional API variants; middleware stripping or rewriting the response body.","solutions":["Retry the command; if persistent, the API contract may have changed — update the library","Log the raw JSON body to confirm the shape","Check the library repo for issues about reply/main response changes"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"null","typeGuard":"function isObjectData(x) { return !!x && typeof x === 'object' && !Array.isArray(x); }","tryCatchPattern":"try { const rows = await run(['bilibili','comments',bvid]); } catch (e) { if (/returned malformed data/.test(e.message)) return retryWithBackoff(fn, 2); throw e; }","preventionTips":["Retry transient shape anomalies with backoff","Report persistent occurrences to the library maintainers with the raw response","Keep the library updated against Bilibili API changes"],"tags":["api-response","schema-validation","upstream-error"],"backgroundTag":"api-malformed-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}