jackwener/OpenCLI · error · ArgumentError
bilibili comment message cannot be empty
Error message
bilibili comment message cannot be empty
What it means
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.
Source
Thrown at clis/bilibili/comment.js:38
name: 'comment',
access: 'write',
description: '在 B站视频下发表评论或回复(官方 API,需登录;消息里的 @用户 会被解析为真实提及)',
domain: 'www.bilibili.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'bvid', required: true, positional: true, help: 'Video BV ID / URL / b23.tv short link' },
{ name: 'message', required: true, positional: true, help: 'Comment text. Any @username in it is resolved to a real mention' },
{ name: 'parent', type: 'int', help: 'top-level/root rpid to reply under (omit for a top-level comment)' },
{ name: 'execute', type: 'boolean', help: 'Actually post the comment. Without it the command refuses to write.' },
],
columns: ['rpid', 'bvid', 'oid', 'message', 'url'],
func: async (page, kwargs) => {
if (!page) {
throw new CommandExecutionError('Browser session required for bilibili comment');
}
const message = String(kwargs.message ?? '').trim();
if (!message)
throw new ArgumentError('bilibili comment message cannot be empty');
// Write guard: posting is public and irreversible-ish, so require an explicit opt-in.
if (!kwargs.execute)
throw new ArgumentError('Refusing to post: pass --execute to actually publish this comment');
const parent = kwargs.parent != null ? readPositiveInteger(kwargs.parent, 'parent') : null;
let bvid;
try {
bvid = await resolveBvid(kwargs.bvid);
}
catch (error) {
throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${String(kwargs.bvid ?? '')}`, error instanceof Error ? error.message : String(error));
}
// Resolve bvid → aid (the reply API addresses videos by aid, as `oid`)
const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });
const viewData = requireOkPayload(view, 'view');
const oid = viewData?.aid;
if (!oid)
throw new CommandExecutionError(`Cannot resolve aid for bvid: ${bvid}`);
// Resolve @username mentions to uids. Bilibili only turns "@name" into a realView on GitHub (pinned to 49907e53dc)
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
Example fix
// before cli bilibili comment --bvid BV1xx --message "$MSG" # MSG empty // after [ -n "$MSG" ] && cli bilibili comment --bvid BV1xx --message "$MSG"
Defensive patterns
Strategy: validation
Validate before calling
const msg = String(message ?? '').trim();
if (!msg) throw new Error('comment message cannot be empty'); Type guard
const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;
Try / catch
try { await commentCmd(); } catch (e) { if (String(e.message).includes('message cannot be empty')) { console.error('Provide a non-empty --message'); } else throw e; } Prevention
- Verify shell variables feeding --message are set
- Quote message arguments
- Trim and check length in scripts before invoking
- Avoid whitespace-only messages
When it happens
Trigger: Invoking the comment command with --message "" or omitting --message entirely (String(undefined ?? '').trim() yields ''), or passing only whitespace.
Common situations: Shell variable holding the message is empty/unset (e.g. $MSG unset); quoting bug discards the argument; template renders to blank in automation scripts.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili unfollow target cannot be empty
- bloomberg businessweek --limit must be an integer between 1
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d9450427dc9317ef.
Report an issue: GitHub.