jackwener/OpenCLI · error · CommandExecutionError
Bilibili ${label} API returned malformed data
Error message
Bilibili ${label} API returned malformed data What it means
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.
Source
Thrown at clis/bilibili/comments.js:52
}
function requireOkPayload(payload, label) {
if (!payload || typeof payload !== 'object' || Array.isArray(payload) || !Object.hasOwn(payload, 'code')) {
throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);
}
if (payload.code !== 0) {
const message = payload.message ?? 'unknown error';
if (isAuthLikeBilibiliError(payload.code, message)) {
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')) {View on GitHub (pinned to 49907e53dc)
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
Example fix
null
Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
function isObjectData(x) { return !!x && typeof x === 'object' && !Array.isArray(x); } Try / catch
try { const rows = await run(['bilibili','comments',bvid]); } catch (e) { if (/returned malformed data/.test(e.message)) return retryWithBackoff(fn, 2); throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Bilibili silently changing the reply API response shape; regional API variants; middleware stripping or rewriting the response body.
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 did not return replies
- Bilibili ${label} API returned malformed 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/cd69ea1a4038ec35.
Report an issue: GitHub.