jackwener/OpenCLI · error · CommandExecutionError
Zhihu answer detail returned a malformed payload
Error message
Zhihu answer detail returned a malformed payload
What it means
This CommandExecutionError is thrown when the parsed response is valid JSON but is not a plain object — typeof data !== 'object' or Array.isArray(data). The library expects the Zhihu answer detail endpoint to return a JSON object; a scalar (string/number), null, or array indicates the response shape is not what the API contract promises.
Source
Thrown at clis/zhihu/answer-detail.js:113
}
if (status === 404) {
throw new EmptyResultError('zhihu answer-detail', `No Zhihu answer was found for ${answerId}.`);
}
throw new CommandExecutionError(
status
? `Zhihu answer detail request failed (HTTP ${status})`
: 'Zhihu answer detail request failed',
'Try again later or rerun with -v for more detail',
);
}
if (data.__malformedJson) {
throw new CommandExecutionError(
`Zhihu answer detail returned malformed JSON: ${data.__malformedJson}`,
'Try again later or rerun with -v for more detail',
);
}
if (typeof data !== 'object' || Array.isArray(data)) {
throw new CommandExecutionError(
'Zhihu answer detail returned a malformed payload',
'Try again later or rerun with -v for more detail',
);
}
if (data.error || data.error_msg || data.message) {
throw new CommandExecutionError(
`Zhihu answer detail returned an error payload: ${data.error?.message || data.error_msg || data.message}`,
'Try again later or rerun with -v for more detail',
);
}
if (!Object.prototype.hasOwnProperty.call(data, 'content')) {
throw new CommandExecutionError(
'Zhihu answer detail payload did not include answer content',
'Try again later or rerun with -v for more detail',
);
}
const question = data.question || {};
// Answer ids and newer question ids can exceedView on GitHub (pinned to 49907e53dc)
Solutions
- Retry later; if Zhihu changed its API shape, update the CLI/library to a version matching the new contract.
- Rerun with -v to capture the raw payload and confirm the unexpected shape.
- Check for library/Zhihu API version drift and pin or upgrade accordingly.
Defensive patterns
Strategy: type-guard
Type guard
function isPlainObject(v) { return typeof v === 'object' && v !== null && !Array.isArray(v); } Try / catch
try {
const detail = await answerDetail(id);
} catch (err) {
if (/malformed payload/.test(err.message)) {
console.error('Zhihu response shape changed — check for CLI/library updates.');
return null;
}
throw err;
} Prevention
- Keep the CLI/library updated against Zhihu API shape changes.
- Narrow the result with an isPlainObject guard in your own wrappers.
- Log raw payloads (with -v) to detect contract drift early.
- Pin a known-good CLI version if Zhihu changes its API mid-project.
When it happens
Trigger: The endpoint returns valid JSON whose top-level value is null, an array, a string, or a number instead of an object (e.g. an array wrapper from an unexpected API version or a bare error string).
Common situations: Zhihu changed or versioned the API response shape, a proxy returned its own JSON error body (array of errors), or hitting a different endpoint that returns a list.
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
- WeRead search API returned an unreadable books payload
- Zhihu answer detail payload did not include answer content
- 12306 ${endpoint} returned an unexpected payload shape
- ${label} returned an unexpected payload shape; expected an o
- archive snapshots returned malformed CDX payload: top-level
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d764c0356ceeb81a.
Report an issue: GitHub.