{"record":{"id":"4a53aac70e1c0ca5","repo":"jackwener/OpenCLI","slug":"failed-to-open-zhihu-answer-answerid-err-ins","errorCode":null,"errorMessage":"Failed to open Zhihu answer ${answerId}: ${err instanceof Error ? err.message : String(err)}","messagePattern":"Failed to open Zhihu answer (.+?): (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer-comments.js","lineNumber":60,"sourceCode":"        }\n        const topLevelLimit = Number(kwargs.limit ?? 20);\n        if (!Number.isInteger(topLevelLimit) || topLevelLimit <= 0 || topLevelLimit > MAX_LIMIT) {\n            throw new ArgumentError(`--limit must be a positive integer no greater than ${MAX_LIMIT}`);\n        }\n        const repliesLimit = Number(kwargs['replies-limit'] ?? 3);\n        if (!Number.isInteger(repliesLimit) || repliesLimit < 0 || repliesLimit > MAX_REPLIES_LIMIT) {\n            throw new ArgumentError(`--replies-limit must be an integer between 0 and ${MAX_REPLIES_LIMIT}`);\n        }\n        const order = String(kwargs.order ?? 'score');\n        if (order !== 'score' && order !== 'latest') {\n            throw new ArgumentError('--order must be score or latest');\n        }\n\n        const { answerId } = target;\n        try {\n            await page.goto(`https://www.zhihu.com/answer/${answerId}`);\n        } catch (err) {\n            throw new CommandExecutionError(\n                `Failed to open Zhihu answer ${answerId}: ${err instanceof Error ? err.message : String(err)}`,\n                '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 questionId = target.questionId || currentQuestionId;\n\n        const roots = await fetchRootComments(page, answerId, order, topLevelLimit);\n        if (roots.length === 0) {\n            throw new EmptyResultError('zhihu answer-comments', `No comments found for answer ${answerId}.`);\n        }\n        const repliesByRoot = await fetchRepliesByRoot(page, roots, repliesLimit);\n        return buildCommentRows(roots, repliesByRoot, { answerId, questionId });\n    },\n});\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-comments.js#L42-L78","documentation":"After argument validation the command navigates Chrome (via the page controller) to https://www.zhihu.com/answer/<answerId>. If page.goto throws (navigation failure, timeout, connection error), the error is wrapped in a CommandExecutionError that includes the answer id and the underlying message, with a hint to open the URL in Chrome and retry.","triggerScenarios":"Network outage or DNS failure; Zhihu returning a hard error/anti-bot block that aborts navigation; page.goto timeout on a slow connection; invalid answer id causing a protocol-level navigation error.","commonSituations":"Corporate proxy or VPN blocking zhihu.com; Chrome not logged in and Zhihu throttling; transient Wi-Fi drops during automation runs; deleted answers leading to abortive redirects.","solutions":["Open the answer URL in Chrome manually, confirm it loads and you are logged in, then retry the command","Check network/VPN/proxy connectivity to zhihu.com","Verify the answer id is valid and the answer is not deleted (test the URL in a browser)","Increase navigation timeout or retry after a delay"],"exampleFix":"// before\nawait page.goto(`https://www.zhihu.com/answer/${answerId}`);\n// after\ntry {\n  await page.goto(`https://www.zhihu.com/answer/${answerId}`);\n} catch (err) {\n  await sleep(2000);\n  await page.goto(`https://www.zhihu.com/answer/${answerId}`);\n}","handlingStrategy":"try-catch","validationCode":"// optional pre-check\nconst reachable = await fetch('https://www.zhihu.com', { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!reachable) throw new Error('zhihu.com unreachable; check network/VPN');","typeGuard":null,"tryCatchPattern":"try { rows = await answerComments(id); }\ncatch (err) {\n  if (err instanceof CommandExecutionError && /Failed to open Zhihu answer/.test(err.message)) {\n    await retryWithBackoff(() => answerComments(id), 3);\n  } else throw err;\n}","preventionTips":["Ensure Chrome is running, logged into Zhihu, and can load the answer manually","Check proxy/VPN settings that could block zhihu.com","Add bounded retries with backoff around navigation-dependent commands","Validate the answer id exists before automating"],"tags":["zhihu","navigation","network","browser-automation"],"backgroundTag":"page-navigation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}