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

  1. Fix the validation: change `Number.isNaN(rid)` to `Number.isNaN(Number(rid))`.
  2. 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).
  3. 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

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


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