jackwener/OpenCLI · error · ArgumentError

bilibili comments --top cannot be combined with --parent (pi

Error message

bilibili comments --top cannot be combined with --parent (pinned comments only exist at the top level)

What it means

An ArgumentError raised when both --top and --parent are passed to bilibili comments. Pinned comments only exist at the top level of a video's comment section, so a nested reply-thread query (--parent) cannot also be filtered to pinned comments; the flags are mutually exclusive by design.

Source

Thrown at clis/bilibili/comments.js:124

    description: '获取 B站视频评论(官方 API;用 --parent <rpid> 读取某条评论下的「楼中楼」回复;用 --top 只看置顶评论)',
    domain: 'www.bilibili.com',
    strategy: Strategy.COOKIE,
    args: [
        { name: 'bvid', required: true, positional: true, help: 'Video BV ID (e.g. BV1WtAGzYEBm)' },
        { name: 'parent', type: 'int', help: 'rpid of a comment — fetch the replies under it instead of top-level comments' },
        { name: 'top', type: 'boolean', default: false, help: '只返回置顶评论(与 --parent 互斥)' },
        { name: 'limit', type: 'int', default: 20, help: 'Number of comments (max 50)' },
    ],
    columns: ['rank', 'rpid', 'author', 'text', 'likes', 'replies', 'time'],
    func: async (page, kwargs) => {
        if (!page) {
            throw new CommandExecutionError('Browser session required for bilibili comments');
        }
        const limit = parseLimit(kwargs.limit);
        const parent = parseParent(kwargs.parent);
        const top = kwargs.top === true;
        if (top && parent != null) {
            throw new ArgumentError('bilibili comments --top cannot be combined with --parent (pinned comments only exist at the top level)');
        }
        let bvid;
        try {
            bvid = await resolveBvid(kwargs.bvid);
        }
        catch (error) {
            throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${String(kwargs.bvid ?? '')}`, error instanceof Error ? error.message : String(error));
        }
        // Resolve bvid → aid (required by reply API)
        const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });
        const viewData = requireOkPayload(view, 'view');
        const aid = viewData?.aid;
        if (!aid)
            throw new CommandExecutionError(`Cannot resolve aid for bvid: ${bvid}`);
        const payload = parent != null
            ? await apiGet(page, '/x/v2/reply/reply', {
                params: { oid: aid, type: 1, root: parent, pn: 1, ps: limit },
            })

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Remove --top when querying replies under a parent rpid
  2. Remove --parent when you want only pinned top-level comments
  3. In scripts, build flags conditionally: pass --top or --parent, never both

Example fix

// before
await run(['bilibili', 'comments', bvid, '--top', '--parent', rpid]);
// after
await run(['bilibili', 'comments', bvid, '--parent', rpid]); // or drop --parent to use --top
Defensive patterns

Strategy: validation

Validate before calling

if (args.includes('--top') && (args.includes('--parent') || parent != null)) {
    throw new Error('--top and --parent are mutually exclusive');
}

Type guard

function isFlagComboValid(kwargs) {
    return !(kwargs.top === true && kwargs.parent != null);
}

Try / catch

try {
    const rows = await bilibiliComments(bvid, { top, parent });
} catch (err) {
    if (err instanceof ArgumentError && /--top cannot be combined/.test(err.message)) {
        // drop one flag and retry
    } else throw err;
}

Prevention

When it happens

Trigger: Running 'bilibili comments <bvid> --top --parent <rpid>' — top is true and parent is a non-null integer.

Common situations: Scripted invocations that always append --top; users assuming --top filters pinned comments inside a sub-thread; copy-pasted flag combos.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f88771f805c9a4fe. Report an issue: GitHub.