DIYgod/RSSHub · error · InvalidParameterError
Invalid room ID. Room ID should be a number.
Error message
Invalid room ID. Room ID should be a number.
What it means
Thrown by the Douyin live room route when the `rid` path parameter fails the numeric validation. This has the same BUG as the hashtag route: `Number.isNaN(rid)` where `rid` is a string from `ctx.req.param()` — `Number.isNaN()` only returns true for the value `NaN`, never for strings, so the check is always `false` and the error is never thrown. Non-numeric room IDs silently pass through and cause failures downstream.
Source
Thrown at lib/routes/douyin/live.ts:36
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['live.douyin.com/:rid'],
},
],
name: '直播间开播',
maintainers: ['TonyRL'],
handler,
};
async function handler(ctx) {
const rid = ctx.req.param('rid');
if (Number.isNaN(rid)) {
throw new InvalidParameterError('Invalid room ID. Room ID should be a number.');
}
const pageUrl = `https://live.douyin.com/${rid}`;
const renderData = await cache.tryGet(
`douyin:live:${rid}`,
async () => {
let roomInfo;
const context = await playwright();
const page = await context.newPage();
await page.route('**/*', (route) => {
const request = route.request();
request.resourceType() === 'document' || request.resourceType() === 'stylesheet' || request.resourceType() === 'script' || request.resourceType() === 'xhr' ? route.continue() : route.abort();
});
page.on('response', async (response) => {
const request = response.request();
if (request.url().includes('/webcast/room/web/enter')) {
roomInfo = await response.json();View on GitHub (pinned to bed535e087)
Solutions
- Fix the validation: change `Number.isNaN(rid)` to `Number.isNaN(Number(rid))`.
- If you are a user (post-fix), ensure rid is the numeric room ID from the Douyin live URL (e.g. https://live.douyin.com/685317364746 → rid=685317364746).
- Find the correct rid from the live.douyin.com URL.
Example fix
// before (BUG: never fires for string input)
const rid = ctx.req.param('rid');
if (Number.isNaN(rid)) {
throw new InvalidParameterError('Invalid room ID. Room ID should be a number.');
}
// after
const rid = ctx.req.param('rid');
if (Number.isNaN(Number(rid))) {
throw new InvalidParameterError('Invalid room ID. Room ID should be a number.');
} Defensive patterns
Strategy: validation
Validate before calling
// Correctly validate that rid is a numeric string
function isValidDouyinRid(rid: string): boolean {
return /^\d+$/.test(rid);
}
const rid = userInput;
if (!isValidDouyinRid(rid)) {
throw new Error(`Invalid room ID '${rid}'. Must be a numeric string.`);
} Type guard
function isNumericRid(value: string): boolean {
return /^\d+$/.test(value);
} Try / catch
try {
const feed = await fetch(`${rsshubUrl}/douyin/live/${rid}`);
} catch (e) {
if (e.message.includes('Invalid room ID')) {
console.error(`rid must be numeric, got: ${rid}`);
}
throw e;
} Prevention
- NOTE: The current validation has the same Number.isNaN() bug as the hashtag route. Validate client-side with /^\d+$/.test(rid).
- Extract the rid from the Douyin live URL: https://live.douyin.com/<rid>.
- If maintaining this route, fix the guard to Number.isNaN(Number(rid)).
When it happens
Trigger: Supplying a non-numeric rid (e.g. /douyin/live/abc) — due to the bug, the validation does NOT fire; the Playwright navigation to live.douyin.com/abc proceeds and either redirects or returns unexpected data, causing a different error downstream (e.g. undefined property access on renderData).
Common situations: Developer expects validation to catch bad input but it doesn't; the error message exists as dead code; fixing the guard to actually reject non-numeric IDs.
Related errors
- Invalid tag ID. Tag ID should be a number.
- Invalid UID. UID should start with <b>MS4wLjABAAAA</b>.
- Invalid category
- At least one valid search parameter is required
- 无法检测 Discuz 版本,请在路由中指定版本参数,如 /discuz/x/ 或 /discuz/7/
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/a55206c9d685f69e.
Report an issue: GitHub.