jackwener/OpenCLI · error · ArgumentError
Answer ID must be a numeric id, a Zhihu answer URL, or answe
Error message
Answer ID must be a numeric id, a Zhihu answer URL, or answer:<qid>:<aid>
What it means
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.
Source
Thrown at clis/zhihu/answer-comments.js:38
cli({
site: 'zhihu',
name: 'answer-comments',
access: 'read',
description: '知乎回答评论列表(保留回复层级)',
domain: 'www.zhihu.com',
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;View on GitHub (pinned to 49907e53dc)
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
Example fix
// before opencli zhihu answer-comments https://www.zhihu.com/question/123 // after opencli zhihu answer-comments https://www.zhihu.com/question/123/answer/1937205528846655537
Defensive patterns
Strategy: validation
Validate before calling
const ANSWER_RE = /^(\d+)$|^https?:\/\/www\.zhihu\.com\/question\/(\d+)\/answer\/(\d+)|^answer:(\d+):(\d+)$/;
if (!ANSWER_RE.test(String(id).trim())) throw new Error('not a valid zhihu answer target'); Type guard
const isAnswerTarget = (v) => typeof v === 'string' && (/^\d+$/.test(v.trim()) || /\/answer\/\d+/.test(v) || /^answer:\d+:\d+$/.test(v.trim()));
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- --limit must be a positive integer no greater than ${MAX_LIM
- --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/1320618123387990.
Report an issue: GitHub.