DIYgod/RSSHub · warning
Invalid rid type
Error message
Invalid rid type
What it means
Defensive default branch in getAPI()'s switch over ridType. ridType comes from the static ridList entries, which only declare three types: 'x/rid', 'pgc/web', 'pgc/season' — all explicitly handled. So with the current ridList this branch is effectively unreachable; it would fire only if someone added a ridList entry with a new `type` string without adding a matching case. It is a programmer/maintainer guard, not a user-facing condition.
Source
Thrown at lib/routes/bilibili/ranking.ts:214
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':
apiBase = 'https://api.bilibili.com/pgc/season/rank/web/list';
apiParams = `day=3&season_type=${numericRid}&web_location=333.934`;
break;
// case 'x/type':
// apiUrl = `https://api.bilibili.com/x/web-interface/ranking?rid=0&type=${numericRid}&web_location=333.934`;
// break;
default:
throw new Error('Invalid rid type');
}
return {
apiBase,
apiParams,
referer: `https://www.bilibili.com/v/popular/rank/${ridEnglish}`,
ridChinese,
ridType,
link: `https://www.bilibili.com/v/popular/rank/${ridEnglish}`,
};
}
async function handler(ctx) {
const isJsonFeed = ctx.req.query('format') === 'json';
const args = ctx.req.param();
if (args.redirect1 || args.redirect2) {
// redirect old routes like /bilibili/ranking/0/3/1 or /bilibili/ranking/0/3/1/xxx
const embedArg = args.redirect2 ? '/' + args.redirect2 : '';View on GitHub (pinned to bed535e087)
Solutions
- If you are extending ridList with a new type, add the corresponding case to the switch in lib/routes/bilibili/ranking.ts and verify the apiBase/apiParams it produces.
- As an end user hitting this, it indicates a bug in the installed RSSHub build — upgrade or downgrade to a release where ridList and getAPI() agree.
- Report the rid you passed and the RSSHub version to the maintainers.
Example fix
// before (ridList extended with type 'x/type' but switch has no case)
// default: throw new Error('Invalid rid type');
// after
switch (ridType) {
case 'x/rid': /* ... */ break;
case 'pgc/web': /* ... */ break;
case 'pgc/season': /* ... */ break;
case 'x/type':
apiBase = 'https://api.bilibili.com/x/web-interface/ranking';
apiParams = `rid=0&type=${numericRid}&web_location=333.934`;
break;
default:
throw new Error(`Invalid rid type: ${ridType}`);
} Defensive patterns
Strategy: validation
Validate before calling
// Maintainer-side: assert every ridList type is handled by the switch.
const HANDLED_TYPES = new Set(['x/rid', 'pgc/web', 'pgc/season']);
function assertRidListTypesCovered(ridList: Record<number, { type: string }>) {
for (const [id, v] of Object.entries(ridList)) {
if (!HANDLED_TYPES.has(v.type)) {
throw new Error(`ridList[${id}] has unhandled type '${v.type}'; add a case to getAPI()`);
}
}
} Type guard
type RidType = 'x/rid' | 'pgc/web' | 'pgc/season';
function isKnownRidType(t: string): t is RidType {
return t === 'x/rid' || t === 'pgc/web' || t === 'pgc/season';
} Try / catch
// Maintainer: throw with the offending type so the bug is diagnosable.
default:
throw new Error(`Invalid rid type: ${ridType as string} (rid=${String(rid)})`); Prevention
- When extending ridList with a new `type`, add the matching case in the same commit and run the ranking tests.
- Add a unit test that iterates ridList and asserts getAPI returns a non-throwing result for every entry.
- Make the default branch message include the ridType value so future regressions are debuggable.
When it happens
Trigger: A contributor adds a new entry to ridList whose `type` is something other than 'x/rid' / 'pgc/web' / 'pgc/season' and forgets to extend the switch; or ridList is mutated at runtime. Not producible by any URL the user can request today.
Common situations: Maintainer extends ridList with a new ranking category (e.g. a future 'live' type) without updating getAPI(); downstream fork diverges from ridList.
Related errors
- Invalid rid
- This type of ranking is not supported yet
- response.message
- 缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值
- 对应 uid 的 Bilibili 用户的 Cookie 已过期
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/1f1d22bc0565b039.
Report an issue: GitHub.