DIYgod/RSSHub · error · InvalidParameterError
Unknown region: ${region}
Error message
Unknown region: ${region} What it means
InvalidParameterError thrown by the Yahoo news handler when the :region segment is not in the allow-list ['hk','tw','au','ca','fr','malaysia','nz','sg','uk',''] (after normalizing en/EN/us/US/www/WWW to the empty US-default string). It guards against unsupported Yahoo regional domains before building any URL.
Source
Thrown at lib/routes/yahoo/news/index.ts:112
| All | US | Politics | World | Science | Tech |
| ------ | -- | -------- | ----- | ------- | ---- |
| (留空) | us | politics | world | science | tech |
再举例,由于 uk.news.yahoo.com/rss/ukoriginal 可以访问并且有较新的新闻,所以 /yahoo/news/uk/ukoriginal 是一个有效的 RSSHub 路由。
\`作者 author\`
对于香港和台湾雅虎,请使用另一个 "新聞來源" 路由。
对于其他雅虎新闻,本路由的 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 : '所有類別'}`,View on GitHub (pinned to bed535e087)
Solutions
- Use one of the supported regions: hk, tw, au, ca, fr, malaysia, nz, sg, uk, or en/us/www for the US default.
- If you need an unsupported region, check whether *.news.yahoo.com/rss/<category> works and request it be added, or use Yahoo's native RSS directly.
- Verify spelling — 'malaysia' is the full word, not 'my'.
Defensive patterns
Strategy: validation
Validate before calling
const US_ALIASES = new Set(['en', 'us', 'www', '']);
const SUPPORTED_REGIONS = new Set(['hk', 'tw', 'au', 'ca', 'fr', 'malaysia', 'nz', 'sg', 'uk', '']);
function normalizeYahooRegion(raw: string | undefined) {
const lower = (raw ?? '').toLowerCase();
const region = US_ALIASES.has(lower) ? '' : lower;
if (!SUPPORTED_REGIONS.has(region)) {
throw new InvalidParameterError(`Unknown region: ${region}. Supported: ${[...SUPPORTED_REGIONS].filter(Boolean).join(', ')} (or en/us/www for US).`);
}
return region;
} Type guard
const SUPPORTED_REGIONS = new Set(['hk', 'tw', 'au', 'ca', 'fr', 'malaysia', 'nz', 'sg', 'uk', '']);
function isYahooRegion(value: string): boolean {
return SUPPORTED_REGIONS.has(value);
} Prevention
- Normalize to lowercase and map US aliases before validating.
- Keep the allow-list in one constant shared by all Yahoo news routes.
- Remember 'malaysia' is the full word, not the ISO code 'my'.
When it happens
Trigger: A request to /yahoo/news/:region/:category where region.lowercase() is outside the allow-list — e.g. /yahoo/news/de/..., /yahoo/news/in/..., or /yahoo/news/japan/.... The normalization step maps several US aliases to '', so those pass; anything else hits the guard.
Common situations: Caller assumed a Yahoo region (e.g. Germany, India, Japan) is supported when only the listed regions are; typo; integrator passed a full hostname instead of a region token.
Related errors
- Unknown category for ${region}: ${category}
- Unsupported region: ${region}
- Unknown region: ${region}
- Unknown region: ${region}
- Invalid language parameter. Use "en" or "zh".
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/1b7f563e2783941e.
Report an issue: GitHub.