jackwener/OpenCLI · error · ArgumentError

Bilibili summary URL must contain a BV video id

Error message

Bilibili summary URL must contain a BV video id

What it means

For URLs on a bilibili.com host, readBvid extracts the BV ID from the path via /\/(?:video|bangumi\/play)\/(BV[A-Za-z0-9]+)/. If the path has no /video/BV... or /bangumi/play/BV... segment, the URL is on the right host but does not point at a video, so this ArgumentError is thrown. The library only scrapes the id from known path shapes rather than fetching the page.

Solutions

  1. Open the video page and copy the full URL including /video/BVxxxx path.
  2. Convert av-numbers to BV ids, or just pass the BV id directly.
  3. Validate the URL contains /video/BV... or /bangumi/play/BV... before invoking.

Example fix

// before
await summaryCommand('https://www.bilibili.com/video/av170001');
// after
await summaryCommand('https://www.bilibili.com/video/BV1xx411c7mD');
Defensive patterns

Strategy: validation

Validate before calling

const u = new URL(input);
if (/(^|\.)bilibili\.com$/.test(u.hostname) && !/\/video\/BV[A-Za-z0-9]+|\/bangumi\/play\/BV[A-Za-z0-9]+/i.test(u.pathname)) {
  throw new Error('URL must be a bilibili video/bangumi page containing /video/BV... or /bangumi/play/BV...');
}

Type guard

function isBilibiliVideoUrl(u) {
  try {
    const url = new URL(u);
    return /(^|\.)bilibili\.com$/i.test(url.hostname) &&
      /\/(?:video|bangumi\/play)\/BV[A-Za-z0-9]+/i.test(url.pathname);
  } catch { return false; }
}

Try / catch

try {
  await summaryCommand(url);
} catch (e) {
  if (/must contain a BV video id/.test(e.message)) {
    console.error('Copy the full video page URL, e.g. https://www.bilibili.com/video/BV1xx411c7mD');
  } else throw e;
}

Prevention

When it happens

Trigger: Passing bilibili.com URLs that are not video pages: `https://www.bilibili.com/` (homepage), `https://space.bilibili.com/123456` (user space), `https://www.bilibili.com/video/av170001` (av-number instead of BV id), or a video URL with the id stripped.

Common situations: Copying the site homepage or a user/space page instead of the video page; using legacy av-number URLs (BV regex requires the literal 'BV' prefix); URL was truncated by a chat/text editor losing the path.

Related errors


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

Appendix: source

Thrown at clis/bilibili/summary.js:43

        throw new ArgumentError('bilibili summary bvid cannot be empty', 'Pass a BV ID, Bilibili video URL, or b23.tv short link.');
    }
    if (BVID_RE.test(input)) {
        return input;
    }
    let parsed = null;
    try {
        parsed = new URL(input);
    } catch {
        // Bare b23.tv short codes are accepted by the shared resolver.
    }
    if (parsed) {
        if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
            throw new ArgumentError('Bilibili summary URL must use http or https');
        }
        if (BILIBILI_HOST_RE.test(parsed.hostname)) {
            const match = parsed.pathname.match(/\/(?:video|bangumi\/play)\/(BV[A-Za-z0-9]+)/i);
            if (!match) {
                throw new ArgumentError('Bilibili summary URL must contain a BV video id');
            }
            return match[1];
        }
        if (!B23_HOST_RE.test(parsed.hostname)) {
            throw new ArgumentError('Bilibili summary URL must be a bilibili.com or b23.tv URL');
        }
    }
    try {
        return await resolveBvid(input);
    } catch (error) {
        throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${input}`, error instanceof Error ? error.message : String(error));
    }
}

function requireOkPayload(payload, label) {
    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
        throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);
    }

View on GitHub (pinned to 49907e53dc)