jackwener/OpenCLI · error · ArgumentError

bilibili comment ${label} must be a positive integer

Error message

bilibili comment ${label} must be a positive integer

What it means

readPositiveInteger strictly validates comment-related numeric arguments (parent rpid). It throws ArgumentError when the value is not an integer or is <= 0, preventing malformed ids from reaching the Bilibili reply API.

Source

Thrown at clis/bilibili/comment.js:13

/**
 * Bilibili comment — posts a top-level comment or a reply on a video via the official API.
 * Uses /x/v2/reply/add, authenticated by the logged-in cookie + bili_jct CSRF token.
 * @username mentions in the message are resolved to real mentions (at_name_to_mid).
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { apiGet, apiPost, requireOkPayload, resolveBvid, resolveUid } from './utils.js';

function readPositiveInteger(value, label) {
    const n = Number(value);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`bilibili comment ${label} must be a positive integer`);
    }
    return n;
}

cli({
    site: 'bilibili',
    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'],

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer rpid, e.g. --parent 123456789012345678
  2. Strip URL fragments/prefixes and quote arguments in the shell
  3. Omit --parent entirely for a top-level comment instead of passing 0
  4. Validate with Number.isInteger(n) && n > 0 in wrapper scripts

Example fix

// before
cli comment --parent 0 ...
// after
cli comment ...        # top-level: omit --parent
cli comment --parent 87654321 ...
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(parentArg);
if (!Number.isInteger(n) || n <= 0) throw new Error(`parent must be a positive integer, got: ${parentArg}`);

Type guard

const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0;

Try / catch

try { await comment({ parent }); } catch (e) { if (/must be a positive integer/.test(e.message)) { console.error('Fix the --parent value'); } else throw e; }

Prevention

When it happens

Trigger: Passing --parent as a non-numeric string (e.g. 'abc'), a float (e.g. '1.5'), zero, or a negative number to bilibili comment subcommands that resolve a parent comment id.

Common situations: Copy-pasting a URL fragment containing the rpid plus extra characters; passing 0 assuming it means 'no parent'; shell quoting issues splitting the value; confusing oid/rpid values.

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


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