{"record":{"id":"60729307ad2103cb","repo":"jackwener/OpenCLI","slug":"zhihu-search-returned-malformed-paging-data","errorCode":null,"errorMessage":"Zhihu search returned malformed paging data","messagePattern":"Zhihu search returned malformed paging data","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/search.js","lineNumber":94,"sourceCode":"    const payload = unwrapEvaluateResult(data);\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError('Zhihu search returned malformed payload');\n    }\n    if (payload.__httpError) {\n        const status = payload.__httpError;\n        if (status === 401 || status === 403) {\n            throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');\n        }\n        throw new CommandExecutionError(`Zhihu search request failed${status ? ` (HTTP ${status})` : ''}`, 'Try again later or rerun with -v for more detail');\n    }\n    if (payload.__fetchError) {\n        throw new CommandExecutionError('Zhihu search request failed', String(payload.__fetchError));\n    }\n    if (!Array.isArray(payload.data)) {\n        throw new CommandExecutionError('Zhihu search returned malformed data list', `URL: ${url}`);\n    }\n    if (!payload.paging || typeof payload.paging !== 'object') {\n        throw new CommandExecutionError('Zhihu search returned malformed paging data', `URL: ${url}`);\n    }\n    return payload;\n}\n\nfunction normalizeResultItem(item) {\n    if (!item || typeof item !== 'object' || item.type !== 'search_result' || !item.object || typeof item.object !== 'object') {\n        return null;\n    }\n    const obj = item.object;\n    if (obj.type !== 'answer' && obj.type !== 'article' && obj.type !== 'question') return null;\n    const key = itemKey(item);\n    const url = itemUrl(obj);\n    const question = obj.question || {};\n    const title = stripHtml(obj.title || question.name || question.title || '');\n    if (!key || !url || !title) {\n        throw new CommandExecutionError('Zhihu search returned malformed result row identity');\n    }\n    return {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/search.js#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the search — intermittent page-load issues can omit paging data","Rerun with -v and compare the raw payload against the expected { data, paging } shape","Limit fetching to the first page (--limit <= PAGE_SIZE 20) to avoid deep-pagination edge cases","Update the CLI if Zhihu changed the paging schema"],"exampleFix":"// before: consuming results then paging blindly\nconst next = results.paging.next;\n// after\nif (!results?.paging) throw new Error('No paging info; stopping pagination');\nconst next = results.paging.next;","handlingStrategy":"type-guard","validationCode":"const payload = unwrapEvaluateResult(rawResponse);\nif (!payload || !payload.paging || typeof payload.paging !== 'object') {\n  throw new Error('Zhihu response lacks paging metadata; single-page processing only');\n}","typeGuard":"function hasPaging(payload) {\n  return !!payload && typeof payload === 'object' && !!payload.paging && typeof payload.paging === 'object';\n}","tryCatchPattern":"try {\n  const results = await searchZhihu(q);\n} catch (err) {\n  if (err instanceof CommandExecutionError && err.message === 'Zhihu search returned malformed paging data') {\n    console.error('Paging info missing; returning first page only.', err.hint);\n    return [];\n  }\n  throw err;\n}","preventionTips":["Avoid deep pagination in one run; fetch pages incrementally with small limits","Handle the last page gracefully in your own code — paging may be absent at the end of results","Rerun with -v to inspect raw payloads when pagination breaks","Update the CLI if Zhihu changes the paging schema"],"tags":["zhihu","schema-mismatch","pagination","malformed-payload"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}