jackwener/OpenCLI · error · CommandExecutionError

Bilibili creator comparison returned malformed metric ${defi

Error message

Bilibili creator comparison returned malformed metric ${definition.key}

What it means

metricValue found the metric key but its value is not a usable non-negative finite number (string, boolean, NaN, Infinity, or negative). The library whitelists fields from an undocumented endpoint and hard-validates each value, so corrupt or type-changed data aborts the command instead of producing bogus statistics.

Source

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

            'The manuscript was not present in the latest 100 creator analytics rows; it may be older, not owned by this account, or not analyzed yet.',
        );
    }
    const target = matches[0];
    if (!isRecord(target.stat)) {
        throw new CommandExecutionError(`Bilibili creator comparison returned malformed stat data for ${bvid}`);
    }
    return target;
}

function metricValue(target, definition) {
    const source = definition.source === 'target' ? target : target.stat;
    if (!Object.prototype.hasOwnProperty.call(source, definition.key)) {
        throw new CommandExecutionError(`Bilibili creator comparison omitted metric ${definition.key}`);
    }
    const raw = source[definition.key];
    if (raw === null) return null;
    if (typeof raw !== 'number' || !Number.isFinite(raw) || raw < 0) {
        throw new CommandExecutionError(`Bilibili creator comparison returned malformed metric ${definition.key}`);
    }
    if (definition.unit === 'percent' && raw > 10_000) {
        throw new CommandExecutionError(`Bilibili creator comparison returned out-of-range percentage ${definition.key}`);
    }
    if ((definition.unit === 'count' || definition.unit === 'seconds') && !Number.isSafeInteger(raw)) {
        throw new CommandExecutionError(`Bilibili creator comparison returned non-integer metric ${definition.key}`);
    }
    return definition.divisor ? raw / definition.divisor : raw;
}

cli({
    site: 'bilibili',
    name: 'creator-stats',
    description: '读取当前账号最近稿件的核心创作指标(需登录创作中心)',
    access: 'read',
    example: 'opencli bilibili creator-stats <bvid-or-video-url> -f json',
    domain: 'member.bilibili.com',
    strategy: Strategy.COOKIE,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command; transient partial writes on Bilibili's side can resolve.
  2. Inspect the raw compare-endpoint response to see the actual value/type for the failing key.
  3. If Bilibili changed the type, update the CLI to coerce/parse the new representation (e.g. strip commas from strings).
  4. Pin/update the CLI version whose validators match the current API.

Example fix

// caller-side tolerant extraction
const raw = target.stat?.[def.key];
const value = typeof raw === 'string' ? Number(raw.replace(/,/g, '')) : raw;
const stat = (typeof value === 'number' && Number.isFinite(value) && value >= 0) ? value : null;
Defensive patterns

Strategy: type-guard

Validate before calling

const raw = row?.stat?.[def.key];
if (!(raw === null || (typeof raw === 'number' && Number.isFinite(raw) && raw >= 0))) { /* treat as unavailable */ }

Type guard

function isNonNegativeFinite(v) {
    return typeof v === 'number' && Number.isFinite(v) && v >= 0;
}

Try / catch

try {
    const rows = await creatorStats(bvid);
} catch (e) {
    if (/malformed metric/.test(e.message)) {
        // retry once, then fall back to null metrics
    } else throw e;
}

Prevention

When it happens

Trigger: target.stat[key] (or the row's duration field) holds a non-number: a string like "1,234" after a Bilibili format change, a float for count metrics, negative counters, or null-adjacent sentinel values other than null.

Common situations: Bilibili changes a field from number to string with formatting; negative corrections make counters negative; floating-point creeping into integer counters; proxies or caches corrupting the payload.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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