{"record":{"id":"8e87e00c6d11451c","repo":"jackwener/OpenCLI","slug":"zhihu-answer-detail-request-failed-err-instance","errorCode":null,"errorMessage":"Zhihu answer detail request failed: ${err instanceof Error ? err.message : String(err)}","messagePattern":"Zhihu answer detail request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer-detail.js","lineNumber":86,"sourceCode":"                'Open the answer URL in Chrome and retry after the page is reachable.',\n            );\n        }\n        const currentQuestionId = page.getCurrentUrl\n            ? extractQuestionIdFromAnswerUrl(await page.getCurrentUrl().catch(() => ''))\n            : '';\n        const apiUrl = `https://www.zhihu.com/api/v4/answers/${answerId}?include=content,voteup_count,comment_count,author,created_time,updated_time,question`;\n        const data = await page.evaluate(`\n      (async () => {\n        const r = await fetch(${JSON.stringify(apiUrl)}, { credentials: 'include' });\n        if (!r.ok) return { __httpError: r.status };\n        try {\n          return await r.json();\n        } catch (error) {\n          return { __malformedJson: error instanceof Error ? error.message : String(error) };\n        }\n      })()\n    `).catch((err) => {\n            throw new CommandExecutionError(\n                `Zhihu answer detail request failed: ${err instanceof Error ? err.message : String(err)}`,\n                'Try again later or rerun with -v for more detail.',\n            );\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            );","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-detail.js#L68-L104","documentation":"This CommandExecutionError wraps any rejection of the in-page fetch script used to request the Zhihu answer detail API. The command evaluates JavaScript inside the page to fetch the answer JSON; if that fetch rejects (network error, page context destroyed, script evaluation failure), it is re-thrown with the original error message appended. The in-page script itself catches JSON parse errors separately, so this error indicates the fetch/evaluation step itself failed, not bad JSON.","triggerScenarios":"The page.evaluate(...) promise rejects: the in-page fetch() throws (network failure, CORS/credentials issue, aborted request), or the page navigated/closed mid-evaluation destroying the execution context.","commonSituations":"Zhihu session invalidated between navigation and fetch, flaky connection dropping the XHR, browser tab crashed or navigated away, or Zhihu anti-bot challenge replacing the page during evaluation.","solutions":["Retry the command; transient fetch failures usually succeed on a second attempt.","Run with -v for more detail to identify whether it is a network vs. page-context error.","Re-authenticate with zhihu.com (log in via the browser profile) if the session expired.","Ensure nothing navigates or closes the page concurrently while the command runs."],"exampleFix":"// before\nconst data = await page.evaluate(fetchScript); // unhandled rejection\n// after\nconst data = await page.evaluate(fetchScript).catch((err) => {\n  throw new CommandExecutionError(`Zhihu answer detail request failed: ${err.message}`);\n});","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isFetchFailure(err) { return err instanceof Error && /Zhihu answer detail request failed/.test(err.message); }","tryCatchPattern":"try {\n  const detail = await answerDetail(id);\n} catch (err) {\n  if (/Zhihu answer detail request failed/.test(err.message)) {\n    return retryWithBackoff(() => answerDetail(id), { attempts: 3, baseMs: 1000 });\n  }\n  throw err;\n}","preventionTips":["Retry transient fetch failures with exponential backoff.","Run with -v to capture the underlying cause before escalating.","Keep the browser page stable (no concurrent navigation) during evaluation.","Refresh Zhihu login sessions periodically for long-running jobs."],"tags":["network","fetch","browser","zhihu"],"backgroundTag":"fetch-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}