jackwener/OpenCLI · error · CommandExecutionError

Bilibili creator comparison API returned malformed list data

Error message

Bilibili creator comparison API returned malformed list data

What it means

After the envelope's `code` passes (code === 0), requirePayload additionally requires payload.data to be a record containing an array `list`. If code is 0 but data/list is missing or of the wrong type, the response is considered contract-violating and this CommandExecutionError is thrown. This guards against success-shaped responses whose payload structure changed.

Source

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

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
            || error instanceof EmptyResultError
            || error instanceof CommandExecutionError
            || error instanceof TimeoutError

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log a sample of the raw payload (when code === 0) to see the new shape and update requirePayload's whitelist (payload.data.list) accordingly
  2. Check whether the account has any manuscripts/analytics; try with an account that has published videos
  3. Pin/retest against the sanitized creator-center probe fixtures to detect a schema drift
  4. If Bilibili migrated the endpoint, find the new field name or endpoint and update the CLI
Defensive patterns

Strategy: validation

Validate before calling

function hasListShape(payload) {
  return payload?.code === 0 && payload.data && !Array.isArray(payload.data) && Array.isArray(payload.data.list);
}
// call the endpoint once with a probe account and assert hasListShape before production use

Type guard

function hasValidListData(payload) {
  return Boolean(payload?.data) && typeof payload.data === 'object' && !Array.isArray(payload.data) && Array.isArray(payload.data.list);
}

Try / catch

try {
  const rows = await runCommand();
} catch (e) {
  if (/malformed list data/.test(e.message)) {
    // capture raw payload for diagnosis; check account has manuscripts / schema drift
  } else throw e;
}

Prevention

When it happens

Trigger: Endpoint returns {code: 0, data: null}, {code: 0, data: {}}, or {code: 0, data: {list: {...}}} — e.g. Bilibili renamed `list`, moved it, or returns no data for accounts with zero analyzable manuscripts.

Common situations: Bilibili silently changing the undocumented response schema; brand-new creator accounts with no rows returning an empty/non-list data; probe fixtures drifting from production behavior.

Understand the failure class

Related errors


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