jackwener/OpenCLI · error · CommandExecutionError

Bilibili comments reply ${index + 1} was missing ctime

Error message

Bilibili comments reply ${index + 1} was missing ctime

What it means

Thrown by formatReplyRow when reply.ctime cannot be converted to a finite number (Number(reply.ctime) is NaN/Infinity). ctime (creation unix timestamp) is required to render the time column, so replies without it are rejected.

Source

Thrown at clis/bilibili/comments.js:89

        throw new CommandExecutionError(`Bilibili ${label} API did not return top_replies`);
    }
    if (!Array.isArray(data.top_replies)) {
        throw new CommandExecutionError(`Bilibili ${label} API returned malformed top_replies`);
    }
    return data.top_replies;
}

function formatReplyRow(reply, index) {
    if (!reply || typeof reply !== 'object' || Array.isArray(reply)) {
        throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was malformed`);
    }
    const rpid = String(reply.rpid ?? '').trim();
    if (!rpid) {
        throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing rpid`);
    }
    const ctime = Number(reply.ctime);
    if (!Number.isFinite(ctime)) {
        throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing ctime`);
    }
    return {
        rank: index + 1,
        rpid,
        author: String(reply.member?.uname ?? ''),
        text: String(reply.content?.message ?? '').replace(/\n/g, ' ').trim(),
        likes: reply.like ?? 0,
        replies: reply.rcount ?? 0,
        time: new Date(ctime * 1000).toISOString().slice(0, 16).replace('T', ' '),
    };
}

cli({
    site: 'bilibili',
    name: 'comments',
    access: 'read',
    description: '获取 B站视频评论(官方 API;用 --parent <rpid> 读取某条评论下的「楼中楼」回复;用 --top 只看置顶评论)',
    domain: 'www.bilibili.com',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry — often a transient anomaly for one entry
  2. Update the CLI to a version matching the current Bilibili reply schema
  3. Pre-sanitize or default ctime if you control the fetching layer
  4. Verify with raw API output whether the field is now named differently

Example fix

// before
const ctime = Number(reply.ctime);
if (!Number.isFinite(ctime)) {
    throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing ctime`);
}
// after
const ctime = Number(reply.ctime ?? 0);
if (!Number.isFinite(ctime)) {
    throw new CommandExecutionError(`Bilibili comments reply ${index + 1} was missing ctime`);
} // or default to 0 and render empty time
Defensive patterns

Strategy: validation

Validate before calling

const badCtime = replies.find((r) => !Number.isFinite(Number(r?.ctime)));
if (badCtime) console.warn('a reply lacks a numeric ctime');

Type guard

function hasCtime(reply) {
    return !!reply && typeof reply === 'object' && Number.isFinite(Number(reply.ctime));
}

Try / catch

try {
    const rows = await bilibiliComments(bvid);
} catch (err) {
    if (/missing ctime/.test(err.message)) {
        // retry or accept rows without a usable timestamp
    } else throw err;
}

Prevention

When it happens

Trigger: A reply object in the API response has ctime missing, null, or a non-numeric value (e.g. a string like '' or an ISO date that Number() rejects as NaN).

Common situations: Pinned or specially injected comment entries lacking timestamps; API schema changes (ctime moved/renamed); proxies that alter numeric fields.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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