jackwener/OpenCLI · error · ArgumentError

bilibili comments parent must be a positive integer rpid

Error message

bilibili comments parent must be a positive integer rpid

What it means

ArgumentError thrown by parseParent when the --parent option (a Bilibili comment rpid used to fetch nested 'floor' replies) is not a positive integer. Null/undefined is allowed (means 'no parent'), but any provided value must coerce via Number() to an integer > 0.

Source

Thrown at clis/bilibili/comments.js:31

    return code === -101 || code === -403 || /登录|账号|权限|forbidden|permission|login/i.test(String(message ?? ''));
}

function parseLimit(value) {
    const raw = value == null ? 20 : value;
    const limit = Number(raw);
    if (!Number.isInteger(limit) || limit <= 0 || limit > MAX_LIMIT) {
        throw new ArgumentError(`bilibili comments limit must be an integer between 1 and ${MAX_LIMIT}`);
    }
    return limit;
}

function parseParent(value) {
    if (value == null) {
        return null;
    }
    const parent = Number(value);
    if (!Number.isInteger(parent) || parent <= 0) {
        throw new ArgumentError('bilibili comments parent must be a positive integer rpid');
    }
    return parent;
}

function requireOkPayload(payload, label) {
    if (!payload || typeof payload !== 'object' || Array.isArray(payload) || !Object.hasOwn(payload, 'code')) {
        throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);
    }
    if (payload.code !== 0) {
        const message = payload.message ?? 'unknown error';
        if (isAuthLikeBilibiliError(payload.code, message)) {
            throw new AuthRequiredError('bilibili.com', `Bilibili ${label} API requires login or permission: ${message} (${payload.code})`);
        }
        throw new CommandExecutionError(`Bilibili ${label} API failed: ${message} (${payload.code})`);
    }
    return payload.data;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the full numeric rpid exactly as shown in the comments table (rank/rpid column)
  2. Verify the rpid is a positive integer string before passing it
  3. Keep rpid as a string in scripts to avoid precision loss, and only pass digits

Example fix

// before
bilibili comments BV1WtAGzYEBm --parent 0
// after
bilibili comments BV1WtAGzYEBm --parent 3498271543
Defensive patterns

Strategy: validation

Validate before calling

function isValidRpid(v) { return v != null && Number.isInteger(Number(v)) && Number(v) > 0; }
if (parent != null && !isValidRpid(parent)) throw new Error('parent must be a positive integer rpid');

Type guard

function isPositiveInt(v) { const n = Number(v); return Number.isInteger(n) && n > 0; }

Try / catch

try { ... } catch (e) { if (/parent must be a positive integer/.test(e.message)) { console.error('bad --parent rpid: ' + parent); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Calling `bilibili comments <bvid> --parent abc`, `--parent 0`, `--parent -1`, or `--parent 12.5`; passing an rpid that was truncated or mangled (e.g. lost precision as a JS number elsewhere).

Common situations: Copy-pasting a partial rpid; treating rpid as a float; shell quoting issues that split the rpid; rpid sourced from JSON parsed with numbers losing precision for very large ids.

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/e02271b35a140bf9. Report an issue: GitHub.