{"record":{"id":"1320618123387990","repo":"jackwener/OpenCLI","slug":"answer-id-must-be-a-numeric-id-a-zhihu-answer-url","errorCode":null,"errorMessage":"Answer ID must be a numeric id, a Zhihu answer URL, or answer:<qid>:<aid>","messagePattern":"Answer ID must be a numeric id, a Zhihu answer URL, or answer:<qid>:<aid>","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer-comments.js","lineNumber":38,"sourceCode":"\ncli({\n    site: 'zhihu',\n    name: 'answer-comments',\n    access: 'read',\n    description: '知乎回答评论列表（保留回复层级）',\n    domain: 'www.zhihu.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'id', required: true, positional: true, help: 'Answer ID, full Zhihu answer URL, or typed target (answer:<qid>:<aid>)' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of top-level comments (max 1000)' },\n        { name: 'replies-limit', type: 'int', default: 3, help: 'Number of replies to include per top-level comment (max 100)' },\n        { name: 'order', default: 'score', choices: ['score', 'latest'], help: 'Root comment order' },\n    ],\n    columns: ['rank', 'comment_rank', 'reply_rank', 'depth', 'id', 'parent_id', 'author', 'reply_to', 'likes', 'created_at', 'url', 'content'],\n    func: async (page, kwargs) => {\n        const target = parseAnswerTarget(kwargs.id);\n        if (!target) {\n            throw new ArgumentError(\n                'Answer ID must be a numeric id, a Zhihu answer URL, or answer:<qid>:<aid>',\n                'Example: opencli zhihu answer-comments 1937205528846655537',\n            );\n        }\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;","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-comments.js#L20-L56","documentation":"answer-comments requires an answer identifier in one of three accepted forms: bare numeric id, a full Zhihu answer URL, or answer:<qid>:<aid>. parseAnswerTarget returns null for anything else, and the command throws this ArgumentError with an example. It exists to give immediate feedback instead of navigating to a malformed URL.","triggerScenarios":"Calling the command with a question id instead of an answer id, an empty/missing --id, a URL of the wrong type (question or article URL), or a malformed answer:<...> string.","commonSituations":"Copy-pasting the wrong id from the Zhihu page; passing a zhihu.com/question/... link; forgetting the id argument entirely; shell quoting stripping the argument.","solutions":["Pass a bare numeric answer id: opencli zhihu answer-comments 1937205528846655537","Or pass the full answer URL: https://www.zhihu.com/question/<qid>/answer/<aid>","Or use the answer:<qid>:<aid> form","Extract the numeric id from the URL path segment after /answer/ if you only have a link"],"exampleFix":"// before\nopencli zhihu answer-comments https://www.zhihu.com/question/123\n// after\nopencli zhihu answer-comments https://www.zhihu.com/question/123/answer/1937205528846655537","handlingStrategy":"validation","validationCode":"const ANSWER_RE = /^(\\d+)$|^https?:\\/\\/www\\.zhihu\\.com\\/question\\/(\\d+)\\/answer\\/(\\d+)|^answer:(\\d+):(\\d+)$/;\nif (!ANSWER_RE.test(String(id).trim())) throw new Error('not a valid zhihu answer target');","typeGuard":"const isAnswerTarget = (v) => typeof v === 'string' && (/^\\d+$/.test(v.trim()) || /\\/answer\\/\\d+/.test(v) || /^answer:\\d+:\\d+$/.test(v.trim()));","tryCatchPattern":null,"preventionTips":["Keep the numeric answer id in a variable, not a hand-edited URL","Strip whitespace/query strings from pasted URLs","Distinguish question ids from answer ids in your tooling"],"tags":["zhihu","argument-validation","cli-input"],"backgroundTag":"invalid-argument-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}