{"record":{"id":"cbe941b51fabe937","repo":"jackwener/OpenCLI","slug":"order-must-be-score-or-latest","errorCode":null,"errorMessage":"--order must be score or latest","messagePattern":"--order must be score or latest","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer-comments.js","lineNumber":53,"sourceCode":"    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;\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) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-comments.js#L35-L71","documentation":"--order accepts only 'score' (sort by upvotes) or 'latest' (chronological). Any other string throws this ArgumentError. The value is validated before any network request so bad sorts fail fast.","triggerScenarios":"--order top, --order vote, --order Score (case-sensitive), or scripts passing an empty/unknown sort value.","commonSituations":"Guessing enum values instead of checking the command help; config files using values from a different CLI; case sensitivity surprises.","solutions":["Use exactly --order score or --order latest","Omit --order to get the default 'score'","Run the command's help to see accepted choices"],"exampleFix":"// before\nopencli zhihu answer-comments 123 --order top\n// after\nopencli zhihu answer-comments 123 --order score","handlingStrategy":"validation","validationCode":"const ORDERS = ['score', 'latest'];\nif (!ORDERS.includes(order)) throw new Error(`--order must be one of ${ORDERS.join('|')}`);","typeGuard":"const isOrder = (v) => v === 'score' || v === 'latest';","tryCatchPattern":null,"preventionTips":["Use the exact lowercase enum values","Read the command's choices from its help/config before mapping external sort values","Centralize the order enum in your wrapper"],"tags":["zhihu","argument-validation","cli-input"],"backgroundTag":"invalid-enum-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}