DIYgod/RSSHub · error · InvalidParameterError

Invalid tag ID. Tag ID should be a number.

Error message

Invalid tag ID. Tag ID should be a number.

What it means

Thrown by the Douyin hashtag route when the `cid` path parameter fails the numeric validation check. However, there is a BUG in the validation: `Number.isNaN(cid)` checks whether `cid` is the value `NaN`, but `cid` is always a string (from `ctx.req.param()`), and `Number.isNaN('any string')` always returns `false`. This means the check NEVER throws — even non-numeric strings like 'abc' pass through and fail later in unexpected ways. The intended check was `Number.isNaN(Number(cid))` or `Number.isNaN(+cid)`.

Source

Thrown at lib/routes/douyin/hashtag.ts:38

        supportBT: false,
        supportPodcast: false,
        supportScihub: false,
    },
    radar: [
        {
            source: ['douyin.com/hashtag/:cid'],
            target: '/hashtag/:cid',
        },
    ],
    name: '标签',
    maintainers: ['TonyRL'],
    handler,
};

async function handler(ctx) {
    const cid = ctx.req.param('cid');
    if (Number.isNaN(cid)) {
        throw new InvalidParameterError('Invalid tag ID. Tag ID should be a number.');
    }
    const routeParams = Object.fromEntries(new URLSearchParams(ctx.req.param('routeParams')));
    const embed = fallback(undefined, queryToBoolean(routeParams.embed), false); // embed video
    const iframe = fallback(undefined, queryToBoolean(routeParams.iframe), false); // embed video in iframe
    const relay = resolveUrl(routeParams.relay, true, true); // embed video behind a reverse proxy

    const tagUrl = `https://www.douyin.com/hashtag/${cid}`;

    const tagData = await cache.tryGet(
        `douyin:hashtag:${cid}`,
        async () => {
            const context = await playwright();
            const page = await context.newPage();
            let awemeList: any = '';
            await page.route('**/*', (route) => {
                const request = route.request();
                request.resourceType() === 'document' || request.resourceType() === 'script' || request.resourceType() === 'xhr' ? route.continue() : route.abort();
            });

View on GitHub (pinned to bed535e087)

Solutions

  1. Fix the validation: change `Number.isNaN(cid)` to `Number.isNaN(Number(cid))` so non-numeric strings are properly rejected.
  2. If you are a user hitting this after the fix, ensure the cid is the numeric hashtag ID from the Douyin hashtag page URL.
  3. Find the correct cid from the URL: https://www.douyin.com/hashtag/<cid>.

Example fix

// before (BUG: Number.isNaN on a string always returns false)
const cid = ctx.req.param('cid');
if (Number.isNaN(cid)) {
    throw new InvalidParameterError('Invalid tag ID. Tag ID should be a number.');
}

// after
const cid = ctx.req.param('cid');
if (Number.isNaN(Number(cid))) {
    throw new InvalidParameterError('Invalid tag ID. Tag ID should be a number.');
}
Defensive patterns

Strategy: validation

Validate before calling

// Correctly validate that cid is a numeric string
function isValidDouyinCid(cid: string): boolean {
    return /^\d+$/.test(cid);
}

const cid = userInput;
if (!isValidDouyinCid(cid)) {
    throw new Error(`Invalid tag ID '${cid}'. Must be a numeric string.`);
}

Type guard

function isNumericCid(value: string): boolean {
    return /^\d+$/.test(value);
}

Try / catch

try {
    const feed = await fetch(`${rsshubUrl}/douyin/hashtag/${cid}/routeParams`);
} catch (e) {
    if (e.message.includes('Invalid tag ID')) {
        console.error(`cid must be numeric, got: ${cid}`);
    }
    throw e;
}

Prevention

When it happens

Trigger: Supplying a non-numeric cid (e.g. /douyin/hashtag/abc) — but due to the bug, this does NOT trigger the error; instead the invalid cid silently passes and the Playwright request to douyin.com/hashtag/abc fails or returns garbage. The error message is effectively dead code under the current implementation.

Common situations: A developer debugging why a non-numeric hashtag ID doesn't produce the expected validation error; fixing the validation to properly reject non-numeric input.

Related errors


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