jackwener/OpenCLI · error · ArgumentError
--limit must be a positive integer no greater than ${MAX_LIM
Error message
--limit must be a positive integer no greater than ${MAX_LIMIT} What it means
The --limit option controls how many root comments are fetched and must be a positive integer no greater than MAX_LIMIT. Non-integers, zero/negative values, or values above the cap throw this ArgumentError. It prevents issuing absurd or hostile pagination requests to Zhihu.
Source
Thrown at clis/zhihu/answer-comments.js:45
strategy: Strategy.COOKIE,
args: [
{ name: 'id', required: true, positional: true, help: 'Answer ID, full Zhihu answer URL, or typed target (answer:<qid>:<aid>)' },
{ name: 'limit', type: 'int', default: 20, help: 'Number of top-level comments (max 1000)' },
{ 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.',
);View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer within the cap, e.g. --limit 50
- Omit --limit entirely to use the default of 20
- Validate/normalize the value in your wrapper script before invoking the CLI
Example fix
// before opencli zhihu answer-comments 123 --limit 0 // after opencli zhihu answer-comments 123 --limit 20
Defensive patterns
Strategy: validation
Validate before calling
const limit = Number(rawLimit ?? 20);
if (!Number.isInteger(limit) || limit <= 0 || limit > MAX_LIMIT) throw new Error(`--limit must be 1..${MAX_LIMIT}`); Type guard
const isValidLimit = (v) => Number.isInteger(v) && v > 0 && v <= MAX_LIMIT;
Try / catch
try { await answerComments({ limit }); }
catch (err) {
if (String(err.message).startsWith('--limit')) { await answerComments({ limit: 20 }); }
else throw err;
} Prevention
- Clamp user-provided limits with Math.min(Math.max(1, n), MAX_LIMIT)
- Never pass 0 or -1 expecting 'unlimited'
- Coerce from strings with Number() and check Number.isInteger
When it happens
Trigger: --limit 0, --limit -5, --limit abc, or a huge number exceeding MAX_LIMIT.
Common situations: Script passing an unset variable so '--limit undefined' is parsed as NaN; users assuming limit means 'unlimited' and passing 0; copying a limit larger than the CLI cap from another tool.
Related errors
- Answer ID must be a numeric id, a Zhihu answer URL, or answe
- --replies-limit must be an integer between 0 and ${MAX_REPLI
- --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/eb4b09827b545b55.
Report an issue: GitHub.