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
- 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).
- If you need bangumi/movie/tv/guochuang/documentary/variety rankings, note those are pgc/* types and explicitly unsupported (see error 112).
- 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
- Derive feed URLs only from the route's parameters.rid.options so you never pass an unsupported slug.
- Subscribe via numeric rid when in doubt — but remember numeric pgc ids (1-7) route to ridType pgc/* which is blocked (error 112).
- Keep a copy of the supported slug list next to your feed reader config and re-check it after RSSHub upgrades.
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
- This type of ranking is not supported yet
- Unknown product: ${product}
- Unknown order: ${order}
- Unknown order: ${order}
- Invalid rid type
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/74860b25dcd1877d.
Report an issue: GitHub.