jackwener/OpenCLI · error · ArgumentError
--replies-limit must be an integer between 0 and ${MAX_REPLI
Error message
--replies-limit must be an integer between 0 and ${MAX_REPLIES_LIMIT} What it means
--replies-limit caps how many replies per root comment are fetched; it must be an integer between 0 and MAX_REPLIES_LIMIT (0 legitimately means 'no replies'). Values outside this range, non-integers, or negatives throw this ArgumentError.
Source
Thrown at clis/zhihu/answer-comments.js:49
{ name: 'replies-limit', type: 'int', default: 3, help: 'Number of replies to include per top-level comment (max 100)' },
{ name: 'order', default: 'score', choices: ['score', 'latest'], help: 'Root comment order' },
],
columns: ['rank', 'comment_rank', 'reply_rank', 'depth', 'id', 'parent_id', 'author', 'reply_to', 'likes', 'created_at', 'url', 'content'],
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(() => ''))
: '';View on GitHub (pinned to 49907e53dc)
Solutions
- Use an integer in [0, MAX_REPLIES_LIMIT], e.g. --replies-limit 10
- Use 0 when you want no replies fetched
- Omit the flag to use the default of 3
Example fix
// before opencli zhihu answer-comments 123 --replies-limit -1 // after opencli zhihu answer-comments 123 --replies-limit 10
Defensive patterns
Strategy: validation
Validate before calling
const rl = Number(rawRepliesLimit ?? 3);
if (!Number.isInteger(rl) || rl < 0 || rl > MAX_REPLIES_LIMIT) throw new Error(`--replies-limit must be 0..${MAX_REPLIES_LIMIT}`); Type guard
const isValidRepliesLimit = (v) => Number.isInteger(v) && v >= 0 && v <= MAX_REPLIES_LIMIT;
Try / catch
try { await answerComments({ 'replies-limit': rl }); }
catch (err) {
if (String(err.message).startsWith('--replies-limit')) { await answerComments({ 'replies-limit': 3 }); }
else throw err;
} Prevention
- Remember 0 is valid (no replies); negatives are not 'unlimited'
- Clamp values into [0, MAX_REPLIES_LIMIT] in wrapper scripts
- Validate before invoking the CLI to fail fast
When it happens
Trigger: --replies-limit -1 (to mean 'unlimited'), a value above MAX_REPLIES_LIMIT, or a non-numeric value.
Common situations: Users expecting -1 or 'all' to fetch every reply; scripts interpolating undefined into the flag; confusion between --limit and --replies-limit semantics.
Related errors
- Answer ID must be a numeric id, a Zhihu answer URL, or answe
- --limit must be a positive integer no greater than ${MAX_LIM
- --order must be score or latest
- Answer ID must be a numeric id, a Zhihu answer URL, or answe
- archive snapshots url cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c1ccf6e6db3952c6.
Report an issue: GitHub.