{"record":{"id":"1f1d22bc0565b039","repo":"DIYgod/RSSHub","slug":"invalid-rid-type","errorCode":null,"errorMessage":"Invalid rid type","messagePattern":"Invalid rid type","errorType":"exception","errorClass":null,"httpStatus":503,"severity":"warning","filePath":"lib/routes/bilibili/ranking.ts","lineNumber":214,"sourceCode":"    let apiParams: string;\n\n    switch (ridType) {\n        case 'x/rid':\n            apiParams = `rid=${numericRid}&type=all&web_location=333.934`;\n            break;\n        case 'pgc/web':\n            apiBase = 'https://api.bilibili.com/pgc/web/rank/list';\n            apiParams = `day=3&season_type=${numericRid}&web_location=333.934`;\n            break;\n        case 'pgc/season':\n            apiBase = 'https://api.bilibili.com/pgc/season/rank/web/list';\n            apiParams = `day=3&season_type=${numericRid}&web_location=333.934`;\n            break;\n        // case 'x/type':\n        //     apiUrl = `https://api.bilibili.com/x/web-interface/ranking?rid=0&type=${numericRid}&web_location=333.934`;\n        //     break;\n        default:\n            throw new Error('Invalid rid type');\n    }\n\n    return {\n        apiBase,\n        apiParams,\n        referer: `https://www.bilibili.com/v/popular/rank/${ridEnglish}`,\n        ridChinese,\n        ridType,\n        link: `https://www.bilibili.com/v/popular/rank/${ridEnglish}`,\n    };\n}\n\nasync function handler(ctx) {\n    const isJsonFeed = ctx.req.query('format') === 'json';\n    const args = ctx.req.param();\n    if (args.redirect1 || args.redirect2) {\n        // redirect old routes like /bilibili/ranking/0/3/1 or /bilibili/ranking/0/3/1/xxx\n        const embedArg = args.redirect2 ? '/' + args.redirect2 : '';","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/ranking.ts#L196-L232","documentation":"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.","triggerScenarios":"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.","commonSituations":"Maintainer extends ridList with a new ranking category (e.g. a future 'live' type) without updating getAPI(); downstream fork diverges from ridList.","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."],"exampleFix":"// before (ridList extended with type 'x/type' but switch has no case)\n//  default: throw new Error('Invalid rid type');\n\n// after\nswitch (ridType) {\n    case 'x/rid': /* ... */ break;\n    case 'pgc/web': /* ... */ break;\n    case 'pgc/season': /* ... */ break;\n    case 'x/type':\n        apiBase = 'https://api.bilibili.com/x/web-interface/ranking';\n        apiParams = `rid=0&type=${numericRid}&web_location=333.934`;\n        break;\n    default:\n        throw new Error(`Invalid rid type: ${ridType}`);\n}","handlingStrategy":"validation","validationCode":"// Maintainer-side: assert every ridList type is handled by the switch.\nconst HANDLED_TYPES = new Set(['x/rid', 'pgc/web', 'pgc/season']);\nfunction assertRidListTypesCovered(ridList: Record<number, { type: string }>) {\n  for (const [id, v] of Object.entries(ridList)) {\n    if (!HANDLED_TYPES.has(v.type)) {\n      throw new Error(`ridList[${id}] has unhandled type '${v.type}'; add a case to getAPI()`);\n    }\n  }\n}","typeGuard":"type RidType = 'x/rid' | 'pgc/web' | 'pgc/season';\nfunction isKnownRidType(t: string): t is RidType {\n  return t === 'x/rid' || t === 'pgc/web' || t === 'pgc/season';\n}","tryCatchPattern":"// Maintainer: throw with the offending type so the bug is diagnosable.\ndefault:\n  throw new Error(`Invalid rid type: ${ridType as string} (rid=${String(rid)})`);","preventionTips":["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."],"tags":["bilibili","ranking","defensive","maintainer","rsshub"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}