{"record":{"id":"1b3b4c97b429dbe5","repo":"DIYgod/RSSHub","slug":"invalid-language-1b3b4c","errorCode":null,"errorMessage":"Invalid language","messagePattern":"Invalid language","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"warning","filePath":"lib/routes/kyodonews/index.tsx","lineNumber":50,"sourceCode":"        {\n            source: ['tchina.kyodonews.net/news/:keyword', 'tchina.kyodonews.net/'],\n            target: '/tchina/:keyword?',\n        },\n    ],\n    name: '最新报道',\n    maintainers: ['Rongronggg9'],\n    handler,\n    description:\n        '`keyword` 为关键词，由于共同网有许多关键词并不在主页列出，此处不一一列举，可从关键词页的 URL 的最后一级路径中提取。如 `日中关系` 的关键词页 URL 为 `https://china.kyodonews.net/news/japan-china_relationship`, 则将 `japan-china_relationship` 填入 `keyword`。特别地，当填入 `rss` 时，将从共同网官方 RSS 中抓取文章；略去时，将从首页抓取最新报道 (注意：首页更新可能比官方 RSS 稍慢)。',\n};\n\nasync function handler(ctx) {\n    const language = ctx.req.param('language') ?? 'china';\n    const keyword = ctx.req.param('keyword') === 'RSS' ? 'rss' : (ctx.req.param('keyword') ?? '');\n\n    // raise error for invalid languages\n    if (!['china', 'tchina'].includes(language)) {\n        throw new InvalidParameterError('Invalid language');\n    }\n\n    const rootUrl = `https://${language}.kyodonews.net`;\n    const currentUrl = `${rootUrl}/${keyword ? (keyword === 'rss' ? 'list/feed/rss4news' : `news/${keyword}`) : ''}`;\n\n    let response;\n    try {\n        response = await got(currentUrl);\n    } catch (error) {\n        const err = error as { response?: { statusCode: number } };\n        throw err.response && err.response.statusCode === 404 ? new InvalidParameterError('Invalid keyword') : error;\n    }\n\n    const $ = load(response.data, { xmlMode: keyword === 'rss' });\n\n    let title, description, image, items;\n    image = `https://${language}-kyodo.ismcdn.jp/common/images/apple-touch-icon-180x180.png`;\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/kyodonews/index.tsx#L32-L68","documentation":"Thrown by the Kyodo News route when the :language path parameter is not one of 'china' (simplified Chinese) or 'tchina' (traditional Chinese). Unlike most language codes, these are site/subdomain selectors for Kyodo's Chinese-edition domains (china.kyodonews.net / tchina.kyodonews.net). An invalid value would produce a non-existent subdomain.","triggerScenarios":"Calling /kyodonews/en/... or /kyodonews/ja/... — Kyodo News' English/Japanese editions are not supported by this route. Also fires for typos like 'chian' or 'China' (case-sensitive, no normalization).","commonSituations":"User assumes standard ISO language codes work. User passes uppercase. A user wants the Japanese domestic service which is a different site entirely and not covered here.","solutions":["Use only 'china' or 'tchina' as the language segment (or omit it — 'china' is the default).","Normalize to lowercase and include valid values in the error message.","Note that an invalid keyword (vs language) produces a separate 'Invalid keyword' error from the 404 handler, so this check is specifically for the language segment."],"exampleFix":"// before\nif (!['china', 'tchina'].includes(language)) {\n    throw new InvalidParameterError('Invalid language');\n}\n\n// after\nconst validLangs = ['china', 'tchina'];\nif (!validLangs.includes(language.toLowerCase())) {\n    throw new InvalidParameterError(`Invalid language '${language}'. Supported: ${validLangs.join(', ')} (Simplified / Traditional Chinese)`);\n}","handlingStrategy":"validation","validationCode":"const VALID_LANGS = ['china', 'tchina'] as const;\ntype KyodoLang = typeof VALID_LANGS[number];\nfunction isKyodoLang(s: string): s is KyodoLang {\n    return (VALID_LANGS as readonly string[]).includes(s.toLowerCase());\n}\nconst language = ctx.req.param('language') ?? 'china';\nif (!isKyodoLang(language)) {\n    throw new InvalidParameterError(`Invalid language '${language}'. Supported: ${VALID_LANGS.join(', ')} (Simplified/Traditional Chinese only)`);\n}","typeGuard":"function isKyodoLang(s: string): s is 'china' | 'tchina' {\n    return ['china', 'tchina'].includes(s.toLowerCase());\n}","tryCatchPattern":null,"preventionTips":["Normalize case before validation.","Document that only Chinese editions are supported (not en/ja) to manage user expectations.","Remember the separate 'Invalid keyword' error handles bad keyword values, not language.","Keep the valid-language list as a typed const to prevent drift."],"tags":["validation","language","parameter","kyodonews","case-sensitivity"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}