jackwener/OpenCLI · error · ArgumentError

bilibili summary bvid cannot be empty

Error message

bilibili summary bvid cannot be empty

What it means

readBvid() normalizes whatever the user passed as the bvid argument and throws this ArgumentError when the value is empty after String-coercion and trimming. The CLI requires an identifier — a bare BV ID, a bilibili.com video URL, or a b23.tv short link — because there is no way to query the conclusion API without one. It is an argument-validation failure, not a network problem.

Source

Thrown at clis/bilibili/summary.js:25

import { apiGet, resolveBvid } from './utils.js';

const BILIBILI_HOST_RE = /(^|\.)bilibili\.com$/i;
const B23_HOST_RE = /(^|\.)b23\.tv$/i;
const BVID_RE = /^BV[A-Za-z0-9]+$/;

function formatTime(seconds) {
    const s = Math.max(0, Math.floor(Number(seconds) || 0));
    const h = Math.floor(s / 3600);
    const m = Math.floor((s % 3600) / 60);
    const sec = s % 60;
    const pad = (n) => String(n).padStart(2, '0');
    return h > 0 ? `${h}:${pad(m)}:${pad(sec)}` : `${pad(m)}:${pad(sec)}`;
}

async function readBvid(raw) {
    const input = String(raw ?? '').trim();
    if (!input) {
        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');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a BV ID (e.g. BV1xx411c7mD), a bilibili.com video/bangumi URL, or a b23.tv short link as the argument.
  2. If the id comes from an env var or config, verify it is set and non-empty before invoking.
  3. Check for quoting mistakes in shell scripts that swallow the argument (e.g. `"$BVID"` expanding to empty).

Example fix

// before
await summaryCommand(process.env.BVID); // env var unset -> empty
// after
if (!process.env.BVID) throw new Error('Set BVID first');
await summaryCommand(process.env.BVID);
Defensive patterns

Strategy: validation

Validate before calling

const input = String(raw ?? '').trim();
if (!input) throw new Error('bvid argument is required: pass a BV ID, bilibili.com video URL, or b23.tv short link');

Type guard

function hasBvid(raw) {
  return typeof raw === 'string' && raw.trim().length > 0;
}

Try / catch

try {
  await summaryCommand(bvid);
} catch (e) {
  if (/bvid cannot be empty/.test(e.message)) {
    console.error('Usage: summary <BVID | bilibili URL | b23.tv link>');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `bvid('')`, `bvid(null)`, `bvid(undefined)`, or passing a whitespace-only string like `' '` to the bilibili summary command; the trimmed input is empty so readBvid at summary.js:25 throws immediately.

Common situations: Scripted invocations where the video id comes from an environment variable or config that is unset (e.g. `bvid="$BVID" cli ...` with BVID empty); piping empty output from a previous command; typos where the argument was dropped entirely.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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