jackwener/OpenCLI · error · CommandExecutionError

Bilibili creator comparison returned non-integer metric ${de

Error message

Bilibili creator comparison returned non-integer metric ${definition.key}

What it means

Count- and seconds-unit metrics must be safe integers; the value passed Number.isFinite/non-negative validation but is fractional (e.g. 3.5 plays) or exceeds Number.MAX_SAFE_INTEGER. The library rejects it because such values indicate scaling or type drift in the undocumented API rather than real counters.

Source

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

    }
    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,
    browser: true,
    navigateBefore: `${MEMBER_ORIGIN}/platform/home`,
    args: [
        {
            name: 'bvid',
            type: 'string',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command to rule out a transient bad payload.
  2. Check the raw value's magnitude: if duration looks like milliseconds, the CLI needs a unit conversion.
  3. Update the CLI to round or rescale if Bilibili legitimately changed the representation.
  4. Use an older manuscript / different video to confirm whether it is data-specific.

Example fix

// caller-side tolerant rounding
const raw = target.stat?.[def.key];
const value = Number.isFinite(raw) && raw >= 0 && !Number.isInteger(raw) ? Math.round(raw) : raw;
Defensive patterns

Strategy: validation

Validate before calling

const raw = row?.stat?.[def.key];
if (typeof raw === 'number' && Number.isFinite(raw) && raw >= 0 && (def.unit === 'count' || def.unit === 'seconds') && !Number.isSafeInteger(raw)) {
    // fractional or overflowed counter: round or reject
}

Type guard

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

Try / catch

try {
    const rows = await creatorStats(bvid);
} catch (e) {
    if (/non-integer metric/.test(e.message)) {
        // fall back to Math.round of raw value or null
    } else throw e;
}

Prevention

When it happens

Trigger: A count metric (play, like, comment, dm, fav, coin, share, total_new_attention_cnt) or the duration field is a non-integer finite number, e.g. an averaged float from a new API version, or a microsecond/millisecond duration causing non-integral seconds.

Common situations: Bilibili switches duration from seconds to milliseconds-fractional values; A/B rollouts return floating-point counters; large counts near MAX_SAFE_INTEGER from data aggregation bugs.

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