jackwener/OpenCLI · error · CommandExecutionError

Cannot resolve aid for bvid: ${bvid}

Error message

Cannot resolve aid for bvid: ${bvid}

What it means

Thrown when the /x/web-interface/view API succeeded (code 0) but its data contains no aid — the numeric article/video ID that the reply endpoints require as oid. The BV ID alone cannot query replies, so the bvid→aid mapping failed and the command cannot proceed.

Source

Thrown at clis/bilibili/comments.js:138

        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 },
            })
            : await apiGet(page, '/x/v2/reply/main', {
                params: { oid: aid, type: 1, mode: 3, ps: top ? 1 : limit },
                signed: true,
            });
        const label = parent != null ? 'reply thread' : 'reply main';
        const data = requireOkPayload(payload, label);
        const replies = top
            ? requireTopReplies(data, label)
            : requireReplies(data, label);
        if (replies.length === 0) {
            if (top) {
                throw new EmptyResultError(`bilibili pinned comments: ${bvid}`);
            }
            throw new EmptyResultError(parent != null ? `bilibili comment replies: ${parent}` : `bilibili comments: ${bvid}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the video is still available and is a regular video (open the URL in a browser)
  2. Use the BV ID of the actual video content, not a bangumi/seasonal page
  3. Check login/cookies if the video is age- or region-restricted and the view API truncates data
  4. Update the library if Bilibili moved the aid field in the view response
Defensive patterns

Strategy: try-catch

Type guard

function hasAid(viewData) {
    return !!viewData && Number.isInteger(viewData.aid) && viewData.aid > 0;
}

Try / catch

try {
    const rows = await bilibiliComments(bvid);
} catch (err) {
    if (/Cannot resolve aid/.test(err.message)) {
        // confirm the video exists/is a regular video, then retry or skip
    } else throw err;
}

Prevention

When it happens

Trigger: Calling bilibili comments with a resolvable bvid whose view payload lacks aid — e.g. deleted/hidden videos, non-video content (bangumi, courses) that uses a different ID scheme, or API responses omitting aid.

Common situations: Video taken down or region-locked after ID resolution; passing a BV ID from a bangumi episode or a seasonal content page; schema change in the view endpoint.

Related errors


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