{"record":{"id":"10e0bbe506caa65e","repo":"jackwener/OpenCLI","slug":"zhihu-answer-comments-10e0bb","errorCode":null,"errorMessage":"zhihu answer-comments","messagePattern":"zhihu answer-comments","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/zhihu/answer-comments.js","lineNumber":72,"sourceCode":"        }\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":54,"sourceCodeEnd":78,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-comments.js#L54-L78","documentation":"If the answer page loads but zero root comments come back, the command throws an EmptyResultError naming the command and the answer id. The library treats 'no comments' as a distinct outcome so callers can distinguish it from failures. Note this throws even when zero comments is legitimately correct — the answer simply has no comments yet.","triggerScenarios":"A brand-new or very obscure answer with no comments; comments disabled for the answer/question; all comments removed by moderation so fetchRootComments returns []; anti-bot serving an empty comments payload while the page loads fine.","commonSituations":"Querying freshly posted answers; scraping answers in locked/closed questions; logged-out sessions getting empty comment lists; region-restricted content.","solutions":["Confirm in a browser that the answer actually has comments","Try another answer id to verify the command works","Handle EmptyResultError as 'no data' rather than a failure in batch scripts","Retry while logged in if Zhihu serves empty payloads to anonymous sessions"],"exampleFix":"// before\nconst rows = await runZhihuAnswerComments(id);\n// after\nlet rows;\ntry { rows = await runZhihuAnswerComments(id); }\ncatch (err) {\n  if (err.name === 'EmptyResultError') rows = [];\n  else throw err;\n}","handlingStrategy":"try-catch","validationCode":"// check the page in a browser or via a quick fetch that comments exist before batch-running","typeGuard":null,"tryCatchPattern":"try { rows = await answerComments(id); }\ncatch (err) {\n  if (err.constructor.name === 'EmptyResultError') rows = []; // no comments on this answer\n  else throw err;\n}","preventionTips":["Treat empty result as expected for new/uncommented answers","Batch-run with per-answer try/catch so one empty answer doesn't abort the run","Retry logged-in if anonymous sessions return empty comment lists"],"tags":["zhihu","empty-result","comments"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}