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
- Verify the video is still available and is a regular video (open the URL in a browser)
- Use the BV ID of the actual video content, not a bangumi/seasonal page
- Check login/cookies if the video is age- or region-restricted and the view API truncates data
- 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
- Verify the video loads in a browser before scripting against it
- Use BV IDs of regular videos, not bangumi/seasonal pages
- Keep cookies valid for restricted videos so the view API returns full data
- Check video availability in bulk jobs and skip unavailable items
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
- Bilibili view API returned a malformed payload during paid-c
- 获取视频分P信息失败: ${error?.message || error}
- 获取视频信息失败: ${err?.message || err}
- 获取视频信息失败: ${view?.message ?? 'unknown'} (${view?.code})
- 无法从 view API 拿到 cid (bvid=${bvid})
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3b41aa90bc66f50b.
Report an issue: GitHub.