jackwener/OpenCLI · error · ArgumentError

Expected an exact BVID or bilibili.com video URL, for exampl

Error message

Expected an exact BVID or bilibili.com video URL, for example BV1xx411c7mD

What it means

parseBvidOrVideoUrl in clis/bilibili/utils.js first checks for an exact BV[0-9A-Za-z]{10} BVID; if the input isn't one, it tries new URL(raw). When the string cannot be parsed as a URL at all, it throws ArgumentError 'Expected an exact BVID or bilibili.com video URL...'. The function is deliberately synchronous and strict — it never falls back to b23.tv short-code network resolution.

Source

Thrown at clis/bilibili/utils.js:24

const EXACT_BVID_RE = /^BV[0-9A-Za-z]{10}$/;
const VIDEO_HOSTS = new Set(['bilibili.com', 'www.bilibili.com', 'm.bilibili.com']);

/**
 * Parse one exact, case-sensitive BVID or a trusted bilibili.com video URL.
 * Unlike the legacy short-link resolver, this is synchronous and never treats
 * malformed input as a b23.tv network lookup.
 */
export function parseBvidOrVideoUrl(value) {
    const raw = String(value ?? '').trim();
    if (EXACT_BVID_RE.test(raw)) return raw;

    let parsed;
    try {
        parsed = new URL(raw);
    }
    catch {
        throw new ArgumentError('Expected an exact BVID or bilibili.com video URL, for example BV1xx411c7mD');
    }
    if (!VIDEO_HOSTS.has(parsed.hostname) || parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port) {
        throw new ArgumentError('Expected a trusted HTTPS bilibili.com video URL without credentials or a custom port');
    }
    const match = parsed.pathname.match(/^\/video\/(BV[0-9A-Za-z]{10})\/?$/);
    if (!match) {
        throw new ArgumentError('Bilibili video URL did not contain an exact case-sensitive BVID');
    }
    return match[1];
}
/**
 * Resolve Bilibili short URL / short code to BV ID.
 * Supports: BV1MV9NBtENN, XYzsqGa, b23.tv/XYzsqGa, https://b23.tv/XYzsqGa
 */
export function resolveBvid(input) {
    const trimmed = String(input).trim();
    if (/^BV[A-Za-z0-9]+$/i.test(trimmed)) {
        return Promise.resolve(trimmed);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an exact 12-character BVID like BV1xx411c7mD
  2. Or pass a full URL: https://www.bilibili.com/video/BV1xx411c7mD/
  3. For b23.tv short links or short codes, use resolveBvid instead of parseBvidOrVideoUrl
  4. Add the https:// scheme if you omitted it

Example fix

// before
parseBvidOrVideoUrl('b23.tv/XYzsqGa');
// after
parseBvidOrVideoUrl('https://www.bilibili.com/video/BV1xx411c7mD/');
Defensive patterns

Strategy: validation

Validate before calling

function isExactBvid(v) {
  return /^BV[0-9A-Za-z]{10}$/.test(String(v ?? '').trim());
}
function isBilibiliVideoUrl(v) {
  try {
    const u = new URL(String(v));
    return /^(www|m)?\.?bilibili\.com$/.test(u.hostname) && /^\/video\/BV[0-9A-Za-z]{10}\/?$/.test(u.pathname);
  } catch { return false; }
}
if (!isExactBvid(input) && !isBilibiliVideoUrl(input)) throw new Error(`Bad bvid input: ${input}`);

Type guard

function isBvid(v) {
  return typeof v === 'string' && /^BV[0-9A-Za-z]{10}$/.test(v);
}

Try / catch

try {
  const bvid = parseBvidOrVideoUrl(input);
} catch (err) {
  if (err instanceof ArgumentError) {
    // input may be a b23.tv short link — fall back to the async resolver
    const bvid = await resolveBvid(input);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling bvid/parseBvidOrVideoUrl with input that is neither a valid BVID nor a parsable absolute URL: a bare short code like 'XYzsqGa', a b23.tv short link, 'BV1' (too short), an empty string, or a URL without a scheme.

Common situations: Passing a b23.tv short link to this strict parser instead of resolveBvid; lowercasing the BVID (BV prefix is case-sensitive, though 'BV' itself must be exact and the rest alphanumeric — actually this error fires before the path check when input isn't URL-like); forgetting 'https://' on a bilibili.com URL.

Related errors


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