jackwener/OpenCLI · error · CommandExecutionError
Bilibili ${label} API did not return top_replies
Error message
Bilibili ${label} API did not return top_replies What it means
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).
Source
Thrown at clis/bilibili/comments.js:71
}
if (!Object.hasOwn(data, 'replies')) {
throw new CommandExecutionError(`Bilibili ${label} API did not return replies`);
}
if (data.replies === null) {
return [];
}
if (!Array.isArray(data.replies)) {
throw new CommandExecutionError(`Bilibili ${label} API returned malformed replies`);
}
return data.replies;
}
function requireTopReplies(data, label) {
if (!data || typeof data !== 'object' || Array.isArray(data)) {
throw new CommandExecutionError(`Bilibili ${label} API returned malformed data`);
}
if (!Object.hasOwn(data, 'top_replies')) {
throw new CommandExecutionError(`Bilibili ${label} API did not return top_replies`);
}
if (!Array.isArray(data.top_replies)) {
throw new CommandExecutionError(`Bilibili ${label} API returned malformed top_replies`);
}
return data.top_replies;
}
function formatReplyRow(reply, index) {
if (!reply || typeof reply !== 'object' || Array.isArray(reply)) {
throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was malformed`);
}
const rpid = String(reply.rpid ?? '').trim();
if (!rpid) {
throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing rpid`);
}
const ctime = Number(reply.ctime);
if (!Number.isFinite(ctime)) {
throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing ctime`);View on GitHub (pinned to 49907e53dc)
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
Example fix
// before bilibili comments BV1WtAGzYEBm --top // -> did not return top_replies // after bilibili comments BV1WtAGzYEBm // fetch all top-level comments instead
Defensive patterns
Strategy: fallback
Validate before calling
// pre-check if you already know the video has no pinned comment const skipTop = !videoHasPinnedComment; // then omit --top
Type guard
function hasTopReplies(d) { return !!d && typeof d === 'object' && !Array.isArray(d) && Object.hasOwn(d, 'top_replies') && Array.isArray(d.top_replies); } Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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).
Common situations: Fetching pinned comments for videos that have never had a pinned comment; API shape drift where top_replies is conditionally omitted.
Related errors
- Bilibili ${label} API returned a malformed payload
- Bilibili ${label} API returned malformed data
- Bilibili ${label} API did not return replies
- Bilibili ${label} API returned malformed replies
- Bilibili conclusion API returned malformed data
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/09054717de87b651.
Report an issue: GitHub.