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

  1. Retry with a different, more common query to rule out a zero-result edge case
  2. Rerun with -v and inspect the raw payload to see what shape actually arrived
  3. Update the CLI if Zhihu changed the response schema (check for a newer version)
  4. 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

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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/d81ea3e56a3c0878. Report an issue: GitHub.