{"record":{"id":"dd0bc7d54a488800","repo":"jackwener/OpenCLI","slug":"zhihu-answer-detail-returned-malformed-json-dat","errorCode":null,"errorMessage":"Zhihu answer detail returned malformed JSON: ${data.__malformedJson}","messagePattern":"Zhihu answer detail returned malformed JSON: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer-detail.js","lineNumber":107,"sourceCode":"            );\n        });\n        if (!data || data.__httpError) {\n            const status = data?.__httpError;\n            if (status === 401 || status === 403) {\n                throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch Zhihu answer detail');\n            }\n            if (status === 404) {\n                throw new EmptyResultError('zhihu answer-detail', `No Zhihu answer was found for ${answerId}.`);\n            }\n            throw new CommandExecutionError(\n                status\n                    ? `Zhihu answer detail request failed (HTTP ${status})`\n                    : 'Zhihu answer detail request failed',\n                'Try again later or rerun with -v for more detail',\n            );\n        }\n        if (data.__malformedJson) {\n            throw new CommandExecutionError(\n                `Zhihu answer detail returned malformed JSON: ${data.__malformedJson}`,\n                'Try again later or rerun with -v for more detail',\n            );\n        }\n        if (typeof data !== 'object' || Array.isArray(data)) {\n            throw new CommandExecutionError(\n                'Zhihu answer detail returned a malformed payload',\n                'Try again later or rerun with -v for more detail',\n            );\n        }\n        if (data.error || data.error_msg || data.message) {\n            throw new CommandExecutionError(\n                `Zhihu answer detail returned an error payload: ${data.error?.message || data.error_msg || data.message}`,\n                'Try again later or rerun with -v for more detail',\n            );\n        }\n        if (!Object.prototype.hasOwnProperty.call(data, 'content')) {\n            throw new CommandExecutionError(","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-detail.js#L89-L125","documentation":"This CommandExecutionError is thrown when the in-page fetch succeeded but response.json() (or equivalent parsing) failed inside the evaluated script; the script returns { __malformedJson: <message> } and the command re-raises it as a command execution error. It means Zhihu returned a body that is not valid JSON — often an HTML error/challenge page instead of the API payload.","triggerScenarios":"The evaluated script's JSON parse throws (caught and returned as data.__malformedJson): the response body was HTML (anti-bot challenge, login wall, error page) or an empty/truncated body.","commonSituations":"Zhihu's anti-crawler served a captcha/HTML page mid-session, a captive proxy rewrote the response, or the endpoint returned an empty 200 body under load.","solutions":["Retry later — transient challenge/HTML responses usually clear on a subsequent attempt.","Open zhihu.com in the browser and complete any captcha/anti-bot challenge, then rerun.","Rerun with -v for more detail; if persistent, re-login to refresh the session.","Check for proxy/MITM software injecting HTML into responses."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isMalformedJsonError(err) { return /malformed JSON/.test(err?.message || ''); }","tryCatchPattern":"try {\n  const detail = await answerDetail(id);\n} catch (err) {\n  if (/malformed JSON/.test(err.message)) {\n    console.error('Non-JSON (likely anti-bot HTML) response — complete any captcha in the browser and retry.');\n    return retryWithBackoff(() => answerDetail(id), { attempts: 3, baseMs: 5000 });\n  }\n  throw err;\n}","preventionTips":["Complete anti-bot challenges in the browser session before bulk runs.","Slow request cadence — HTML challenge pages often follow aggressive scraping.","Disable intercepting proxies/MITM tools that rewrite response bodies.","Retry with backoff; challenge responses are frequently transient."],"tags":["json","parsing","anti-bot","zhihu"],"backgroundTag":"malformed-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}