{"record":{"id":"09054717de87b651","repo":"jackwener/OpenCLI","slug":"bilibili-label-api-did-not-return-top-replies","errorCode":null,"errorMessage":"Bilibili ${label} API did not return top_replies","messagePattern":"Bilibili (.+?) API did not return top_replies","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":71,"sourceCode":"    }\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')) {\n        throw new CommandExecutionError(`Bilibili ${label} API did not return top_replies`);\n    }\n    if (!Array.isArray(data.top_replies)) {\n        throw new CommandExecutionError(`Bilibili ${label} API returned malformed top_replies`);\n    }\n    return data.top_replies;\n}\n\nfunction formatReplyRow(reply, index) {\n    if (!reply || typeof reply !== 'object' || Array.isArray(reply)) {\n        throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was malformed`);\n    }\n    const rpid = String(reply.rpid ?? '').trim();\n    if (!rpid) {\n        throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing rpid`);\n    }\n    const ctime = Number(reply.ctime);\n    if (!Number.isFinite(ctime)) {\n        throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing ctime`);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L53-L89","documentation":"CommandExecutionError thrown by requireTopReplies when the successful reply payload's data has no `top_replies` key. Bilibili includes `top_replies` only for the top-level reply/main response; its absence for a --top request means the expected field is missing (pinned comment data absent or shape changed).","triggerScenarios":"Running `bilibili comments <bvid> --top` on a video whose API response omits `top_replies` entirely (most videos have no pinned comment, but the library treats a missing key as a contract violation rather than an empty result).","commonSituations":"Fetching pinned comments for videos that have never had a pinned comment; API shape drift where top_replies is conditionally omitted.","solutions":["Drop --top and fetch regular comments instead — a missing top_replies usually means no pinned comment exists","Check whether data.top_replies is null vs absent in the raw response and treat absence as an empty result","Update the library if this occurs on videos known to have pinned comments"],"exampleFix":"// before\nbilibili comments BV1WtAGzYEBm --top   // -> did not return top_replies\n// after\nbilibili comments BV1WtAGzYEBm        // fetch all top-level comments instead","handlingStrategy":"fallback","validationCode":"// pre-check if you already know the video has no pinned comment\nconst skipTop = !videoHasPinnedComment; // then omit --top","typeGuard":"function hasTopReplies(d) { return !!d && typeof d === 'object' && !Array.isArray(d) && Object.hasOwn(d, 'top_replies') && Array.isArray(d.top_replies); }","tryCatchPattern":"try { rows = await run(['bilibili','comments',bvid,'--top']); } catch (e) { if (/did not return top_replies/.test(e.message)) { rows = await run(['bilibili','comments',bvid]); } else throw e; }","preventionTips":["Assume most videos have no pinned comment; treat missing top_replies as empty and fall back","Only use --top when you know a pin exists","Handle the error as an empty-result case rather than a hard failure"],"tags":["api-response","schema-validation","cli-options"],"backgroundTag":"api-malformed-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}