DIYgod/RSSHub · error · InvalidParameterError

Unknown category for ${region}: ${category}

Error message

Unknown category for ${region}: ${category}

What it means

InvalidParameterError thrown by the Yahoo news handler for the hk/tw branches only. After region passes, if a category was supplied it must be a key of regionConfig[region].categoryMap, because each region has a distinct category set (hk and tw differ) and the category drives the tags sent to getArchive.

Source

Thrown at lib/routes/yahoo/news/index.ts:120

对于香港和台湾雅虎,请使用另一个 "新聞來源" 路由。

对于其他雅虎新闻,本路由的 RSS 中提供了 author 字段,可使用 RSSHub 的内置 "内容过滤" 功能,例如 /yahoo-wg/news/tw/technology?filter\\_author=Yahoo%20Tech|Engadget 可从台湾雅虎的科技新闻中过滤出作者名称中包含 Yahoo Tech 或者 Engadget 的新闻,即瘾科技中文版。`,
    },
};

async function handler(ctx) {
    const region = ['en', 'EN', 'us', 'US', 'www', 'WWW', ''].includes(ctx.req.param('region')) ? '' : ctx.req.param('region').toLowerCase();
    const category = ctx.req.param('category');
    if (!['hk', 'tw', 'au', 'ca', 'fr', 'malaysia', 'nz', 'sg', 'uk', ''].includes(region)) {
        throw new InvalidParameterError(`Unknown region: ${region}`);
    }

    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;

    if (['hk', 'tw'].includes(region)) {
        const { categoryMap } = regionConfig[region];
        if (category && !Object.hasOwn(categoryMap, category)) {
            throw new InvalidParameterError(`Unknown category for ${region}: ${category}`);
        }
        const tags = category ? categoryMap[category].tags : undefined;

        const response = await getArchive(region, limit, tags);
        const list = parseList(region, response);

        const items = await Promise.all(list.map((item) => parseItem(item)));

        return {
            title: `Yahoo 新聞 ${region.toUpperCase()} - ${category ? categoryMap[category].name : '所有類別'}`,
            link: `https://${region}.news.yahoo.com/${category ? `${category}/` : ''}archive`,
            image: 'https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo-1200x1200.png',
            item: items,
        };
    }
    const rssUrl = `https://${region ? `${region}.` : ''}news.yahoo.com/rss/${category ? `${category}/` : ''}`;
    const feed = await parser.parseURL(rssUrl);
    const filteredItems = feed.items.filter((item) => item?.link && !item.link.includes('promotions') && new URL(item.link).hostname.match(/.*\.yahoo\.com$/));

View on GitHub (pinned to bed535e087)

Solutions

  1. Consult the route documentation's per-region category tables and use a category valid for the chosen region.
  2. Omit the category segment to fetch all categories for that region.
  3. If the site added a section, add it to regionConfig[region].categoryMap.
Defensive patterns

Strategy: validation

Validate before calling

function resolveYahooCategory(region: string, category: string | undefined, categoryMap: Record<string, { tags: unknown; name: string }>) {
    if (!category) return undefined;
    if (!Object.hasOwn(categoryMap, category)) {
        throw new InvalidParameterError(`Unknown category for ${region}: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);
    }
    return category;
}

Type guard

function isYahooCategory(categoryMap: Record<string, unknown>, value: string): boolean {
    return Object.hasOwn(categoryMap, value);
}

Prevention

When it happens

Trigger: A request like /yahoo/news/hk/politics or /yahoo/news/tw/hong-kong where the category is valid for one region but not the other, or is entirely unknown. The guard fires inside the `if (['hk','tw'].includes(region))` block before getArchive is called.

Common situations: Caller reused an hk category on tw or vice-versa (e.g. 'hong-kong' is hk-only, 'politics' is tw-only); typo; category was removed in a regionConfig update.

Related errors


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