{"record":{"id":"d9450427dc9317ef","repo":"jackwener/OpenCLI","slug":"bilibili-comment-message-cannot-be-empty","errorCode":null,"errorMessage":"bilibili comment message cannot be empty","messagePattern":"bilibili comment message cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comment.js","lineNumber":38,"sourceCode":"    name: 'comment',\n    access: 'write',\n    description: '在 B站视频下发表评论或回复（官方 API，需登录；消息里的 @用户 会被解析为真实提及）',\n    domain: 'www.bilibili.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'bvid', required: true, positional: true, help: 'Video BV ID / URL / b23.tv short link' },\n        { name: 'message', required: true, positional: true, help: 'Comment text. Any @username in it is resolved to a real mention' },\n        { name: 'parent', type: 'int', help: 'top-level/root rpid to reply under (omit for a top-level comment)' },\n        { name: 'execute', type: 'boolean', help: 'Actually post the comment. Without it the command refuses to write.' },\n    ],\n    columns: ['rpid', 'bvid', 'oid', 'message', 'url'],\n    func: async (page, kwargs) => {\n        if (!page) {\n            throw new CommandExecutionError('Browser session required for bilibili comment');\n        }\n        const message = String(kwargs.message ?? '').trim();\n        if (!message)\n            throw new ArgumentError('bilibili comment message cannot be empty');\n        // Write guard: posting is public and irreversible-ish, so require an explicit opt-in.\n        if (!kwargs.execute)\n            throw new ArgumentError('Refusing to post: pass --execute to actually publish this comment');\n        const parent = kwargs.parent != null ? readPositiveInteger(kwargs.parent, 'parent') : null;\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 (the reply API addresses videos by aid, as `oid`)\n        const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });\n        const viewData = requireOkPayload(view, 'view');\n        const oid = viewData?.aid;\n        if (!oid)\n            throw new CommandExecutionError(`Cannot resolve aid for bvid: ${bvid}`);\n        // Resolve @username mentions to uids. Bilibili only turns \"@name\" into a real","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comment.js#L20-L56","documentation":"The comment text is trimmed and must be non-empty; an empty message would be rejected by Bilibili anyway, so the library fails fast with ArgumentError before making any network call.","triggerScenarios":"Invoking the comment command with --message \"\" or omitting --message entirely (String(undefined ?? '').trim() yields ''), or passing only whitespace.","commonSituations":"Shell variable holding the message is empty/unset (e.g. $MSG unset); quoting bug discards the argument; template renders to blank in automation scripts.","solutions":["Pass a non-empty --message value","Check that any shell variable/CI input feeding --message is non-empty before running","Quote the argument properly so it isn't swallowed","Validate message.length > 0 in calling scripts"],"exampleFix":"// before\ncli bilibili comment --bvid BV1xx --message \"$MSG\"   # MSG empty\n// after\n[ -n \"$MSG\" ] && cli bilibili comment --bvid BV1xx --message \"$MSG\"","handlingStrategy":"validation","validationCode":"const msg = String(message ?? '').trim();\nif (!msg) throw new Error('comment message cannot be empty');","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try { await commentCmd(); } catch (e) { if (String(e.message).includes('message cannot be empty')) { console.error('Provide a non-empty --message'); } else throw e; }","preventionTips":["Verify shell variables feeding --message are set","Quote message arguments","Trim and check length in scripts before invoking","Avoid whitespace-only messages"],"tags":["argument-validation","input-validation","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}