{"record":{"id":"b6b315789be31cd9","repo":"jackwener/OpenCLI","slug":"cannot-resolve-bilibili-bv-id-from-input-string-b6b315","errorCode":null,"errorMessage":"Cannot resolve Bilibili BV ID from input: ${String(kwargs.bvid ?? '')}","messagePattern":"Cannot resolve Bilibili BV ID from input: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":131,"sourceCode":"        { name: 'limit', type: 'int', default: 20, help: 'Number of comments (max 50)' },\n    ],\n    columns: ['rank', 'rpid', 'author', 'text', 'likes', 'replies', 'time'],\n    func: async (page, kwargs) => {\n        if (!page) {\n            throw new CommandExecutionError('Browser session required for bilibili comments');\n        }\n        const limit = parseLimit(kwargs.limit);\n        const parent = parseParent(kwargs.parent);\n        const top = kwargs.top === true;\n        if (top && parent != null) {\n            throw new ArgumentError('bilibili comments --top cannot be combined with --parent (pinned comments only exist at the top level)');\n        }\n        let bvid;\n        try {\n            bvid = await resolveBvid(kwargs.bvid);\n        }\n        catch (error) {\n            throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${String(kwargs.bvid ?? '')}`, error instanceof Error ? error.message : String(error));\n        }\n        // Resolve bvid → aid (required by reply API)\n        const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });\n        const viewData = requireOkPayload(view, 'view');\n        const aid = viewData?.aid;\n        if (!aid)\n            throw new CommandExecutionError(`Cannot resolve aid for bvid: ${bvid}`);\n        const payload = parent != null\n            ? await apiGet(page, '/x/v2/reply/reply', {\n                params: { oid: aid, type: 1, root: parent, pn: 1, ps: limit },\n            })\n            : await apiGet(page, '/x/v2/reply/main', {\n                params: { oid: aid, type: 1, mode: 3, ps: top ? 1 : limit },\n                signed: true,\n            });\n        const label = parent != null ? 'reply thread' : 'reply main';\n        const data = requireOkPayload(payload, label);\n        const replies = top","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L113-L149","documentation":"An ArgumentError wrapping a failure from resolveBvid: the CLI could not turn the user-supplied input (kwargs.bvid) into a valid Bilibili BV ID. The original error message is attached as the cause, and the raw input is echoed in the message (empty string when undefined).","triggerScenarios":"Passing something that resolveBvid cannot parse — a malformed BV ID, a full URL variant it doesn't recognize, an AV number when only BV is accepted, or an empty/undefined bvid.","commonSituations":"Copy-pasting a short link (b23.tv) or mobile URL that the resolver doesn't handle; typos in the BV ID; passing a title or search term instead of an ID; forgetting the positional argument.","solutions":["Pass a canonical BV ID like BV1WtAGzYEBm as the positional argument","Check the cause message for the resolver's specific complaint (bad format vs failed network resolution)","Resolve the URL to a BV ID yourself before invoking if using short links","Verify no stray whitespace/characters were copied into the argument"],"exampleFix":"// before\nbilibili comments \"https://b23.tv/abc123\"\nbilibili comments av170001\n// after\nbilibili comments BV1WtAGzYEBm","handlingStrategy":"validation","validationCode":"const BV_RE = /^BV[0-9A-Za-z]{10}$/;\nif (!BV_RE.test(String(bvid ?? '').trim())) {\n    throw new Error(`input is not a canonical BV ID: ${bvid}`);\n}","typeGuard":"function isBvid(input) {\n    return typeof input === 'string' && /^BV[0-9A-Za-z]{10}$/.test(input.trim());\n}","tryCatchPattern":"try {\n    const rows = await bilibiliComments(input);\n} catch (err) {\n    if (err instanceof ArgumentError && /Cannot resolve Bilibili BV ID/.test(err.message)) {\n        // normalize the URL/input to a BV ID and retry\n    } else throw err;\n}","preventionTips":["Normalize short links (b23.tv) and URLs to a BV ID before calling","Trim whitespace and avoid copy-paste artifacts","Pass only canonical BV IDs like BV1WtAGzYEBm","Read the cause message to distinguish format vs network failures"],"tags":["bilibili","argument-error","input-validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}