jackwener/OpenCLI · error · CommandExecutionError
Bilibili ${label} API returned malformed replies
Error message
Bilibili ${label} API returned malformed replies What it means
CommandExecutionError thrown by requireReplies when data.replies exists and is not null but is not an array. Bilibili's contract is replies: Reply[] | null; any other type is treated as a malformed response.
Source
Thrown at clis/bilibili/comments.js:61
throw new AuthRequiredError('bilibili.com', `Bilibili ${label} API requires login or permission: ${message} (${payload.code})`);
}
throw new CommandExecutionError(`Bilibili ${label} API failed: ${message} (${payload.code})`);
}
return payload.data;
}
function requireReplies(data, label) {
if (!data || typeof data !== 'object' || Array.isArray(data)) {
throw new CommandExecutionError(`Bilibili ${label} API returned malformed data`);
}
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) {View on GitHub (pinned to 49907e53dc)
Solutions
- Retry to rule out a transient corruption
- Disable proxies/extensions that might rewrite the response
- Update the library if Bilibili changed the field type
Example fix
null
Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
function isRepliesArray(d) { return !!d && (d.replies === null || Array.isArray(d.replies)); } Try / catch
try { const rows = await run(['bilibili','comments',bvid]); } catch (e) { if (/malformed replies/.test(e.message)) return retryWithBackoff(fn, 2); throw e; } Prevention
- Validate replies is Array|null before consuming it downstream
- Rule out proxies/extensions rewriting JSON bodies
- Track Bilibili API version changes
When it happens
Trigger: API returns data.replies as an object, string, or number — typically due to a response-shape change or an intermediary rewriting the JSON.
Common situations: API version drift; corrupted/proxied responses; custom middleware or browser extensions modifying response bodies.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Bilibili ${label} API returned malformed data
- Bilibili ${label} API did not return replies
- Bilibili ${label} API returned a malformed payload
- Bilibili ${label} API failed: ${message} (${payload.code})
- Bilibili ${label} API did not return top_replies
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cf811d95c51535ad.
Report an issue: GitHub.