jackwener/OpenCLI · error · CommandExecutionError

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

Error message

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

What it means

Thrown by formatReplyRow when a reply object has no usable rpid (the comment's unique ID): String(reply.rpid ?? '').trim() yields an empty string. The rpid is required output and needed for --parent follow-up queries, so a reply without one cannot be returned.

Source

Thrown at clis/bilibili/comments.js:85

    if (!data || typeof data !== 'object' || Array.isArray(data)) {
        throw new CommandExecutionError(`Bilibili ${label} API returned malformed data`);
    }
    if (!Object.hasOwn(data, 'top_replies')) {
        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',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command; the affected comment may reappear with a valid rpid
  2. Fetch fewer comments (--limit) or skip the offending page
  3. Check whether the library version expects rpid while the API now returns rpid_str or another field, and update
  4. Report the specific video/rpid upstream if reproducible
Defensive patterns

Strategy: validation

Validate before calling

const replyMissingRpid = replies.find((r) => !String(r?.rpid ?? '').trim());
if (replyMissingRpid) console.warn('a reply is missing rpid');

Type guard

function hasRpid(reply) {
    return !!reply && typeof reply === 'object' && String(reply.rpid ?? '').trim().length > 0;
}

Try / catch

try {
    const rows = await bilibiliComments(bvid);
} catch (err) {
    if (/missing rpid/.test(err.message)) {
        // retry or skip the offending comment
    } else throw err;
}

Prevention

When it happens

Trigger: API returns reply objects lacking the rpid field or with rpid null/empty — e.g. in /x/v2/reply/main or /x/v2/reply/reply responses for comments in an inconsistent state.

Common situations: Deleted or shadow-removed comments still present in the list; older API payloads where the id field is named differently; scraping layers that strip 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/b6150ff67043968d. Report an issue: GitHub.