{"record":{"id":"dc97c342a9ac73a7","repo":"jackwener/OpenCLI","slug":"zhihu-search-returned-malformed-payload","errorCode":null,"errorMessage":"Zhihu search returned malformed payload","messagePattern":"Zhihu search returned malformed payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/search.js","lineNumber":78,"sourceCode":"}\n\nfunction requireType(value) {\n    const type = String(value || 'all');\n    if (!TYPES.includes(type)) {\n        throw new ArgumentError(`zhihu search --type must be one of: ${TYPES.join(', ')}`, 'Example: opencli zhihu search codex --type answer');\n    }\n    return type;\n}\n\nfunction unwrapEvaluateResult(payload) {\n    if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;\n    return payload;\n}\n\nfunction requireSearchPayload(data, url) {\n    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;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/search.js#L60-L96","documentation":"requireSearchPayload could not normalize the Browser Bridge response into a usable object: unwrapEvaluateResult returned null, a non-object, or an array. The CLI throws CommandExecutionError because the Zhihu search page/bridge returned data in an unexpected shape, so results cannot be parsed.","triggerScenarios":"Running zhihu search when the in-page evaluation returns nothing (page navigated away, script blocked), the Bridge wraps the payload differently than expected ('data'/'session' envelope missing), or the page returned an error string/array instead of an object.","commonSituations":"Chrome not fully loaded on www.zhihu.com; a Zhihu interstitial/captcha page replacing the normal page; outdated Browser Bridge protocol after an extension update; network drop mid-evaluation.","solutions":["Re-run the search — transient page-load issues often resolve on retry","Verify Chrome and the Browser Bridge extension are running and connected","Ensure the page is actually www.zhihu.com search results, not a captcha/login interstitial","Update the CLI/extension if versions mismatched (envelope format change)","Rerun with -v for verbose output to inspect the raw payload"],"exampleFix":"// before: assuming payload always parses\nconst results = await searchZhihu(q);\n// after\ntry { const results = await searchZhihu(q); }\ncatch (err) { if (err instanceof CommandExecutionError) { await reconnectBridge(); retry(); } throw err; }","handlingStrategy":"try-catch","validationCode":"// pre-flight: confirm the bridge session is alive\nconst probe = await bridge.evaluate('1 + 1');\nif (!probe) throw new Error('Browser Bridge not responding; reconnect Chrome before searching');","typeGuard":"function isUsablePayload(data) {\n  const p = data && typeof data === 'object' && 'data' in data && 'session' in data ? data.data : data;\n  return !!p && typeof p === 'object' && !Array.isArray(p);\n}","tryCatchPattern":"try {\n  const results = await searchZhihu(q);\n} catch (err) {\n  if (err instanceof CommandExecutionError && err.message === 'Zhihu search returned malformed payload') {\n    await reconnectBridge();\n    return searchZhihu(q); // retry once\n  }\n  throw err;\n}","preventionTips":["Keep the Browser Bridge extension and CLI versions in sync","Ensure the Chrome tab is on www.zhihu.com and fully loaded before searching","Dismiss any captcha/login interstitials before running batch searches","Run with -v when developing to catch payload-shape changes early"],"tags":["zhihu","malformed-payload","browser-bridge","parsing"],"backgroundTag":"malformed-response-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}