DIYgod/RSSHub · error

Invalid rid

Error message

Invalid rid

What it means

Thrown by the bilibili ranking route's getAPI() helper when the `rid` path parameter is a non-numeric token that does not match any `english` value in the static ridList table (the supported English slugs like 'all','douga','music',...). The handler only reaches the Object.entries(...).find(...) lookup for non-numeric rids; a failure there means the slug is unknown to RSSHub. This is a user-input validation error, not a network/upstream failure.

Source

Thrown at lib/routes/bilibili/ranking.ts:188

    handler,
};

function getAPI(isNumericRid: boolean, rid: string | number) {
    if (isNumericRid) {
        const zone = ridList[rid as number];
        return {
            apiBase: 'https://api.bilibili.com/x/web-interface/ranking/v2',
            apiParams: `rid=${rid}&type=all&web_location=333.934`,
            referer: 'https://www.bilibili.com/v/popular/rank/all',
            ridChinese: zone?.chinese ?? '',
            ridType: 'x/rid',
            link: 'https://www.bilibili.com/v/popular/rank/all',
        };
    }

    const zone = Object.entries(ridList).find(([_, v]) => v.english === rid);
    if (!zone) {
        throw new Error('Invalid rid');
    }
    const numericRid = zone[0];
    const ridType = zone[1].type;
    const ridChinese = zone[1].chinese;
    const ridEnglish = zone[1].english;

    let apiBase = 'https://api.bilibili.com/x/web-interface/ranking/v2';
    let apiParams: string;

    switch (ridType) {
        case 'x/rid':
            apiParams = `rid=${numericRid}&type=all&web_location=333.934`;
            break;
        case 'pgc/web':
            apiBase = 'https://api.bilibili.com/pgc/web/rank/list';
            apiParams = `day=3&season_type=${numericRid}&web_location=333.934`;
            break;
        case 'pgc/season':

View on GitHub (pinned to bed535e087)

Solutions

  1. Use a supported English slug from the route's `parameters.rid.options` (all, douga, game, kichiku, music, dance, cinephile, ent, knowledge, tech, food, car, fashion, sports, animal) or a valid numeric rid (0, 1001–1024).
  2. If you need bangumi/movie/tv/guochuang/documentary/variety rankings, note those are pgc/* types and explicitly unsupported (see error 112).
  3. Strip trailing slashes or query artifacts from the path so the slug matches exactly.

Example fix

// before
//   /bilibili/ranking/anime   -> throws 'Invalid rid' (no such slug)
//   /bilibili/ranking/musc     -> throws 'Invalid rid' (typo)

// after
//   /bilibili/ranking/all
//   /bilibili/ranking/music
//   /bilibili/ranking/1003      (numeric rid for music)
Defensive patterns

Strategy: validation

Validate before calling

// Validate the rid against the supported slugs before calling getAPI().
import { config } from '@/config'; // (ridList is module-private in ranking.ts; expose it or mirror it)

const SUPPORTED_RID_SLUGS = new Set([
  'all','douga','game','kichiku','music','dance','cinephile','ent',
  'knowledge','tech','food','car','fashion','sports','animal',
]);
const SUPPORTED_NUMERIC_RIDS = new Set([0,1001,1002,1003,1004,1005,1007,1008,1010,1012,1013,1014,1018,1020,1024]);

function isValidRankingRid(rid: string): boolean {
  if (/^\d+$/.test(rid)) return SUPPORTED_NUMERIC_RIDS.has(Number(rid));
  return SUPPORTED_RID_SLUGS.has(rid);
}

Type guard

function isSupportedRankingSlug(rid: string): rid is string {
  return ['all','douga','game','kichiku','music','dance','cinephile','ent','knowledge','tech','food','car','fashion','sports','animal'].includes(rid);
}

Try / catch

try {
  const { ridType } = getAPI(isNumericRid, rid);
  // ...
} catch (e) {
  if (e instanceof Error && e.message === 'Invalid rid') {
    ctx.status = 404;
    ctx.body = { error: `Unknown rid '${rid}'. Use one of: all, douga, game, ...` };
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: GET /bilibili/ranking/:rid where :rid is non-numeric and not one of the supported English slugs — e.g. /bilibili/ranking/foobar, /bilibili/ranking/anime (anime is not in ridList; the bangumi slug is 'bangumi'), or a typo like /bilibili/ranking/musc.

Common situations: Reader subscribes to a slug that does not exist; user guesses a region name that differs from RSSHub's english mapping; outdated documentation pointing at a retired slug; numeric rid passed with trailing characters so the /^\d+$/ test fails.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/74860b25dcd1877d. Report an issue: GitHub.