jackwener/OpenCLI · error · CommandExecutionError
Zhihu search returned malformed data list
Error message
Zhihu search returned malformed data list
What it means
requireSearchPayload validated that the response's payload.data field is an array and it was not (missing, null, or another type). The CLI throws CommandExecutionError because it cannot iterate results without a list, even though the overall payload shape was otherwise acceptable.
Source
Thrown at clis/zhihu/search.js:91
}
function requireSearchPayload(data, url) {
const payload = unwrapEvaluateResult(data);
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError('Zhihu search returned malformed payload');
}
if (payload.__httpError) {
const status = payload.__httpError;
if (status === 401 || status === 403) {
throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');
}
throw new CommandExecutionError(`Zhihu search request failed${status ? ` (HTTP ${status})` : ''}`, 'Try again later or rerun with -v for more detail');
}
if (payload.__fetchError) {
throw new CommandExecutionError('Zhihu search request failed', String(payload.__fetchError));
}
if (!Array.isArray(payload.data)) {
throw new CommandExecutionError('Zhihu search returned malformed data list', `URL: ${url}`);
}
if (!payload.paging || typeof payload.paging !== 'object') {
throw new CommandExecutionError('Zhihu search returned malformed paging data', `URL: ${url}`);
}
return payload;
}
function normalizeResultItem(item) {
if (!item || typeof item !== 'object' || item.type !== 'search_result' || !item.object || typeof item.object !== 'object') {
return null;
}
const obj = item.object;
if (obj.type !== 'answer' && obj.type !== 'article' && obj.type !== 'question') return null;
const key = itemKey(item);
const url = itemUrl(obj);
const question = obj.question || {};
const title = stripHtml(obj.title || question.name || question.title || '');
if (!key || !url || !title) {View on GitHub (pinned to 49907e53dc)
Solutions
- Retry with a different, more common query to rule out a zero-result edge case
- Rerun with -v and inspect the raw payload to see what shape actually arrived
- Update the CLI if Zhihu changed the response schema (check for a newer version)
- Disable browser extensions that rewrite page/network responses and retry
Example fix
// before
const items = results.data.map(normalizeResultItem);
// after
if (!Array.isArray(results?.data)) throw new Error('Unexpected Zhihu search shape');
const items = results.data.map(normalizeResultItem); Defensive patterns
Strategy: type-guard
Validate before calling
const payload = unwrapEvaluateResult(rawResponse);
if (!payload || typeof payload !== 'object' || !Array.isArray(payload.data)) {
throw new Error('Zhihu response lacks a data array; aborting result processing');
} Type guard
function hasDataArray(payload) {
return !!payload && typeof payload === 'object' && !Array.isArray(payload) && Array.isArray(payload.data);
} Try / catch
try {
const results = await searchZhihu(q);
} catch (err) {
if (err instanceof CommandExecutionError && err.message === 'Zhihu search returned malformed data list') {
console.error('Zhihu response schema may have changed; update the CLI or retry with a different query.');
return [];
}
throw err;
} Prevention
- Pin and update the CLI so response-schema changes upstream are picked up
- Treat payload.data defensively in downstream code even when the CLI returns successfully
- Test searches with both common and obscure queries to catch zero-result edge cases
- Disable extensions that mutate JSON responses during development
When it happens
Trigger: Zhihu's search endpoint returned 200/valid JSON but without the expected data array — e.g. an empty object, a result wrapper renamed upstream, or the in-page script built the payload incorrectly when zero results matched an unusual query.
Common situations: Zhihu silently changing the search API response schema; queries returning no hits but also omitting the data key; API responses intercepted by an extension modifying the JSON.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Zhihu search returned malformed payload
- Zhihu search returned malformed paging data
- ${command} parser returned an unexpected shape
- ${command} parser returned row ${index + 1} without required
- Xianyu search response did not include an items array
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d81ea3e56a3c0878.
Report an issue: GitHub.