jackwener/OpenCLI · error · CommandExecutionError

Bilibili creator comparison API failed: ${message} (${payloa

Error message

Bilibili creator comparison API failed: ${message} (${payload.code})

What it means

Generic failure branch of requirePayload: the envelope is well formed but `code` is a non-zero value that is not auth-like. The Bilibili message (payload.message/msg) and numeric code are surfaced verbatim in a CommandExecutionError. Because this endpoint is undocumented, arbitrary negative Bilibili codes (rate-limit, permission, internal) land here.

Source

Thrown at clis/bilibili/creator-stats.js:57

    return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
}

function isAuthLike(code, message) {
    return code === -101
        || code === -111
        || /登录|账号未登录|login required|not logged in/i.test(String(message ?? ''));
}

function requirePayload(payload) {
    if (!isRecord(payload) || !Number.isSafeInteger(payload.code)) {
        throw new CommandExecutionError('Bilibili creator comparison API returned a malformed envelope');
    }
    const message = String(payload.message ?? payload.msg ?? 'unknown error');
    if (payload.code !== 0) {
        if (isAuthLike(payload.code, message)) {
            throw new AuthRequiredError('member.bilibili.com', `Bilibili creator-center login is required: ${message}`);
        }
        throw new CommandExecutionError(`Bilibili creator comparison API failed: ${message} (${payload.code})`);
    }
    if (!isRecord(payload.data) || !Array.isArray(payload.data.list)) {
        throw new CommandExecutionError('Bilibili creator comparison API returned malformed list data');
    }
    return payload.data.list;
}

async function fetchComparison(page) {
    try {
        const payload = await page.fetchJson(
            `${MEMBER_ORIGIN}/x/web/data/archive_diagnose/compare?size=100`,
            { timeoutMs: FETCH_TIMEOUT_SECONDS * 1000 },
        );
        return requirePayload(payload);
    }
    catch (error) {
        if (
            error instanceof AuthRequiredError

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the numeric code and Chinese message in the error to identify the Bilibili business error and act on it (e.g. -412 → slow down / wait, then retry)
  2. Retry after a backoff if the code indicates rate limiting or a transient server error
  3. Verify the account still has creator-center access for the requested analytics
  4. If the code persists, check whether Bilibili changed/retired the undocumented compare endpoint
Defensive patterns

Strategy: retry

Try / catch

try {
  const rows = await runCommand();
} catch (e) {
  const m = /\((\-?\d+)\)$/.exec(e.message);
  const code = m ? Number(m[1]) : null;
  if (code === -412) { /* rate limited: back off exponentially and retry */ }
  else if (code === -403) { /* permission: check account scope */ }
  else throw e;
}

Prevention

When it happens

Trigger: fetchJson on archive_diagnose/compare returns e.g. {code: -412, message: '请求被拦截'} or {code: -403, ...} — any business error other than -101/-111 or login-text messages.

Common situations: Bilibili rate-limiting or risk-control blocking the request (-412); account lacking permission for the analytics scope; transient Bilibili server errors (-500); endpoint deprecated or moved on the server side.

Related errors


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