jackwener/OpenCLI · error · AuthRequiredError

Bilibili ${label} API requires login or permission: ${messag

Error message

Bilibili ${label} API requires login or permission: ${message} (${payload.code})

What it means

AuthRequiredError thrown by requireOkPayload when the Bilibili API responds with code !== 0 that looks auth-related (code -101 or -403, or a message matching login/account/permission keywords such as 登录/账号/权限). The CLI runs with a cookie session (Strategy.COOKIE), so this means your bilibili.com session is missing, expired, or lacks permission.

Source

Thrown at clis/bilibili/comments.js:43

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;
}

function requireReplies(data, label) {
    if (!data || typeof data !== 'object' || Array.isArray(data)) {
        throw new CommandExecutionError(`Bilibili ${label} API returned malformed data`);
    }
    if (!Object.hasOwn(data, 'replies')) {
        throw new CommandExecutionError(`Bilibili ${label} API did not return replies`);
    }
    if (data.replies === null) {
        return [];
    }
    if (!Array.isArray(data.replies)) {
        throw new CommandExecutionError(`Bilibili ${label} API returned malformed replies`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in to bilibili.com in the browser session used by the CLI and refresh the cookie
  2. Re-run the command after re-authenticating
  3. Verify the video's comments are publicly accessible; try another video to confirm it's auth-related

Example fix

// before
bilibili comments BV1WtAGzYEBm  // -> AuthRequiredError (-101 账号未登录)
// after
// 1) open bilibili.com in the CLI's browser profile and log in
// 2) retry
bilibili comments BV1WtAGzYEBm
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

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

Try / catch

try { const rows = await run(['bilibili','comments',bvid]); } catch (e) { if (/requires login or permission/.test(e.message)) { console.error('Bilibili login required — re-authenticate the cookie session'); process.exitCode = 3; } else throw e; }

Prevention

When it happens

Trigger: Calling `bilibili comments <bvid>` (or with --parent/--top) while logged out, with an expired cookie, or on a video whose comments require login/permission; API returns {-101: '账号未登录'} or {-403: '权限不足'} (or message contains 账号/权限/forbidden).

Common situations: Cookie expired after inactivity; running on a headless/CI browser with no login; comments restricted for the video or region; account flagged by risk control.

Related errors


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