{"record":{"id":"006ae228a548b257","repo":"DIYgod/RSSHub","slug":"unknown-category-for-region-category","errorCode":null,"errorMessage":"Unknown category for ${region}: ${category}","messagePattern":"Unknown category for (.+?): (.+?)","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":503,"severity":"error","filePath":"lib/routes/yahoo/news/index.ts","lineNumber":120,"sourceCode":"对于香港和台湾雅虎，请使用另一个 \"新聞來源\" 路由。\n\n对于其他雅虎新闻，本路由的 RSS 中提供了 author 字段，可使用 RSSHub 的内置 \"内容过滤\" 功能，例如 /yahoo-wg/news/tw/technology?filter\\\\_author=Yahoo%20Tech|Engadget 可从台湾雅虎的科技新闻中过滤出作者名称中包含 Yahoo Tech 或者 Engadget 的新闻，即瘾科技中文版。`,\n    },\n};\n\nasync function handler(ctx) {\n    const region = ['en', 'EN', 'us', 'US', 'www', 'WWW', ''].includes(ctx.req.param('region')) ? '' : ctx.req.param('region').toLowerCase();\n    const category = ctx.req.param('category');\n    if (!['hk', 'tw', 'au', 'ca', 'fr', 'malaysia', 'nz', 'sg', 'uk', ''].includes(region)) {\n        throw new InvalidParameterError(`Unknown region: ${region}`);\n    }\n\n    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;\n\n    if (['hk', 'tw'].includes(region)) {\n        const { categoryMap } = regionConfig[region];\n        if (category && !Object.hasOwn(categoryMap, category)) {\n            throw new InvalidParameterError(`Unknown category for ${region}: ${category}`);\n        }\n        const tags = category ? categoryMap[category].tags : undefined;\n\n        const response = await getArchive(region, limit, tags);\n        const list = parseList(region, response);\n\n        const items = await Promise.all(list.map((item) => parseItem(item)));\n\n        return {\n            title: `Yahoo 新聞 ${region.toUpperCase()} - ${category ? categoryMap[category].name : '所有類別'}`,\n            link: `https://${region}.news.yahoo.com/${category ? `${category}/` : ''}archive`,\n            image: 'https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo-1200x1200.png',\n            item: items,\n        };\n    }\n    const rssUrl = `https://${region ? `${region}.` : ''}news.yahoo.com/rss/${category ? `${category}/` : ''}`;\n    const feed = await parser.parseURL(rssUrl);\n    const filteredItems = feed.items.filter((item) => item?.link && !item.link.includes('promotions') && new URL(item.link).hostname.match(/.*\\.yahoo\\.com$/));","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/yahoo/news/index.ts#L102-L138","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Consult the route documentation's per-region category tables and use a category valid for the chosen region.","Omit the category segment to fetch all categories for that region.","If the site added a section, add it to regionConfig[region].categoryMap."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function resolveYahooCategory(region: string, category: string | undefined, categoryMap: Record<string, { tags: unknown; name: string }>) {\n    if (!category) return undefined;\n    if (!Object.hasOwn(categoryMap, category)) {\n        throw new InvalidParameterError(`Unknown category for ${region}: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);\n    }\n    return category;\n}","typeGuard":"function isYahooCategory(categoryMap: Record<string, unknown>, value: string): boolean {\n    return Object.hasOwn(categoryMap, value);\n}","tryCatchPattern":null,"preventionTips":["Remember hk and tw have different category sets — do not reuse across regions.","Derive the allow-list from regionConfig[region].categoryMap so it stays in sync.","Omit the category segment to fetch all categories."],"tags":["yahoo","validation","route-param","category","region"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}