{"record":{"id":"208c3d237b60d417","repo":"jackwener/OpenCLI","slug":"bilibili-summary-bvid-cannot-be-empty","errorCode":null,"errorMessage":"bilibili summary bvid cannot be empty","messagePattern":"bilibili summary bvid cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/summary.js","lineNumber":25,"sourceCode":"import { apiGet, resolveBvid } from './utils.js';\n\nconst BILIBILI_HOST_RE = /(^|\\.)bilibili\\.com$/i;\nconst B23_HOST_RE = /(^|\\.)b23\\.tv$/i;\nconst BVID_RE = /^BV[A-Za-z0-9]+$/;\n\nfunction formatTime(seconds) {\n    const s = Math.max(0, Math.floor(Number(seconds) || 0));\n    const h = Math.floor(s / 3600);\n    const m = Math.floor((s % 3600) / 60);\n    const sec = s % 60;\n    const pad = (n) => String(n).padStart(2, '0');\n    return h > 0 ? `${h}:${pad(m)}:${pad(sec)}` : `${pad(m)}:${pad(sec)}`;\n}\n\nasync function readBvid(raw) {\n    const input = String(raw ?? '').trim();\n    if (!input) {\n        throw new ArgumentError('bilibili summary bvid cannot be empty', 'Pass a BV ID, Bilibili video URL, or b23.tv short link.');\n    }\n    if (BVID_RE.test(input)) {\n        return input;\n    }\n    let parsed = null;\n    try {\n        parsed = new URL(input);\n    } catch {\n        // Bare b23.tv short codes are accepted by the shared resolver.\n    }\n    if (parsed) {\n        if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {\n            throw new ArgumentError('Bilibili summary URL must use http or https');\n        }\n        if (BILIBILI_HOST_RE.test(parsed.hostname)) {\n            const match = parsed.pathname.match(/\\/(?:video|bangumi\\/play)\\/(BV[A-Za-z0-9]+)/i);\n            if (!match) {\n                throw new ArgumentError('Bilibili summary URL must contain a BV video id');","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/summary.js#L7-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a BV ID (e.g. BV1xx411c7mD), a bilibili.com video/bangumi URL, or a b23.tv short link as the argument.","If the id comes from an env var or config, verify it is set and non-empty before invoking.","Check for quoting mistakes in shell scripts that swallow the argument (e.g. `\"$BVID\"` expanding to empty)."],"exampleFix":"// before\nawait summaryCommand(process.env.BVID); // env var unset -> empty\n// after\nif (!process.env.BVID) throw new Error('Set BVID first');\nawait summaryCommand(process.env.BVID);","handlingStrategy":"validation","validationCode":"const input = String(raw ?? '').trim();\nif (!input) throw new Error('bvid argument is required: pass a BV ID, bilibili.com video URL, or b23.tv short link');","typeGuard":"function hasBvid(raw) {\n  return typeof raw === 'string' && raw.trim().length > 0;\n}","tryCatchPattern":"try {\n  await summaryCommand(bvid);\n} catch (e) {\n  if (/bvid cannot be empty/.test(e.message)) {\n    console.error('Usage: summary <BVID | bilibili URL | b23.tv link>');\n  } else throw e;\n}","preventionTips":["Validate required CLI args before invoking (non-empty after trim).","Avoid interpolating unset env vars directly into command args.","Fail fast in scripts with an explicit check that the id variable is set."],"tags":["argument-validation","cli","input-missing"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}