jackwener/OpenCLI · error · ArgumentError
--order must be score or latest
Error message
--order must be score or latest
What it means
--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.
Solutions
- Use exactly --order score or --order latest
- Omit --order to get the default 'score'
- Run the command's help to see accepted choices
Example fix
// before opencli zhihu answer-comments 123 --order top // after opencli zhihu answer-comments 123 --order score
Defensive patterns
Strategy: validation
Validate before calling
const ORDERS = ['score', 'latest'];
if (!ORDERS.includes(order)) throw new Error(`--order must be one of ${ORDERS.join('|')}`); Type guard
const isOrder = (v) => v === 'score' || v === 'latest';
Prevention
- 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
When it happens
Trigger: --order top, --order vote, --order Score (case-sensitive), or scripts passing an empty/unknown sort value.
Common situations: Guessing enum values instead of checking the command help; config files using values from a different CLI; case sensitivity surprises.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Answer ID must be a numeric id, a Zhihu answer URL, or…
- Answer ID must be a numeric id, a Zhihu answer URL, or…
- --limit must be a positive integer no greater than
- --replies-limit must be an integer between 0 and
- archive snapshots must be a digit-only timestamp…
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cbe941b51fabe937.
Report an issue: GitHub.
Appendix: source
Thrown at clis/zhihu/answer-comments.js:53
func: async (page, kwargs) => {
const target = parseAnswerTarget(kwargs.id);
if (!target) {
throw new ArgumentError(
'Answer ID must be a numeric id, a Zhihu answer URL, or answer:<qid>:<aid>',
'Example: opencli zhihu answer-comments 1937205528846655537',
);
}
const topLevelLimit = Number(kwargs.limit ?? 20);
if (!Number.isInteger(topLevelLimit) || topLevelLimit <= 0 || topLevelLimit > MAX_LIMIT) {
throw new ArgumentError(`--limit must be a positive integer no greater than ${MAX_LIMIT}`);
}
const repliesLimit = Number(kwargs['replies-limit'] ?? 3);
if (!Number.isInteger(repliesLimit) || repliesLimit < 0 || repliesLimit > MAX_REPLIES_LIMIT) {
throw new ArgumentError(`--replies-limit must be an integer between 0 and ${MAX_REPLIES_LIMIT}`);
}
const order = String(kwargs.order ?? 'score');
if (order !== 'score' && order !== 'latest') {
throw new ArgumentError('--order must be score or latest');
}
const { answerId } = target;
try {
await page.goto(`https://www.zhihu.com/answer/${answerId}`);
} catch (err) {
throw new CommandExecutionError(
`Failed to open Zhihu answer ${answerId}: ${err instanceof Error ? err.message : String(err)}`,
'Open the answer URL in Chrome and retry after the page is reachable.',
);
}
const currentQuestionId = page.getCurrentUrl
? extractQuestionIdFromAnswerUrl(await page.getCurrentUrl().catch(() => ''))
: '';
const questionId = target.questionId || currentQuestionId;
const roots = await fetchRootComments(page, answerId, order, topLevelLimit);
if (roots.length === 0) {View on GitHub (pinned to 49907e53dc)