jackwener/OpenCLI · error · CommandExecutionError

Zhihu search returned malformed paging data

Error message

Zhihu search returned malformed paging data

What it means

requireSearchPayload found payload.data to be a valid array but payload.paging missing or not an object. Paging metadata (offset/next cursor) is required for the CLI's pagination logic, so it throws CommandExecutionError with the searched URL attached as detail. Results may exist but cannot be paginated safely.

Source

Thrown at clis/zhihu/search.js:94

    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) {
        throw new CommandExecutionError('Zhihu search returned malformed result row identity');
    }
    return {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the search — intermittent page-load issues can omit paging data
  2. Rerun with -v and compare the raw payload against the expected { data, paging } shape
  3. Limit fetching to the first page (--limit <= PAGE_SIZE 20) to avoid deep-pagination edge cases
  4. Update the CLI if Zhihu changed the paging schema

Example fix

// before: consuming results then paging blindly
const next = results.paging.next;
// after
if (!results?.paging) throw new Error('No paging info; stopping pagination');
const next = results.paging.next;
Defensive patterns

Strategy: type-guard

Validate before calling

const payload = unwrapEvaluateResult(rawResponse);
if (!payload || !payload.paging || typeof payload.paging !== 'object') {
  throw new Error('Zhihu response lacks paging metadata; single-page processing only');
}

Type guard

function hasPaging(payload) {
  return !!payload && typeof payload === 'object' && !!payload.paging && typeof payload.paging === 'object';
}

Try / catch

try {
  const results = await searchZhihu(q);
} catch (err) {
  if (err instanceof CommandExecutionError && err.message === 'Zhihu search returned malformed paging data') {
    console.error('Paging info missing; returning first page only.', err.hint);
    return [];
  }
  throw err;
}

Prevention

When it happens

Trigger: Zhihu's search response omitted the paging object (schema change, last-page response format differing, or the in-page collector failing to capture pagination info) while still returning a data array.

Common situations: Zhihu A/B-testing a new search response format; deep pagination reaching a terminal page where paging is omitted; partial page loads where the pagination widget never initialized.

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/60729307ad2103cb. Report an issue: GitHub.