{"record":{"id":"5b16cafb58e6f0c5","repo":"DIYgod/RSSHub","slug":"invalid-language-5b16ca","errorCode":null,"errorMessage":"Invalid language","messagePattern":"Invalid language","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"warning","filePath":"lib/routes/kpmg/insights.tsx","lineNumber":84,"sourceCode":"            <>\n                <br />\n                {raw(content)}\n            </>\n        ) : null}\n        {pdf ? (\n            <>\n                <br />\n                {raw(pdf)}\n            </>\n        ) : null}\n    </>\n);\n\nconst handler = async (ctx: Context) => {\n    const { lang = 'en' } = ctx.req.param();\n    const endpoint = endpoints[lang];\n    if (!endpoint) {\n        throw new InvalidParameterError('Invalid language');\n    }\n    const link = endpoint.link;\n\n    const response = await ofetch(endpoint.api, {\n        method: 'POST',\n        body: payload,\n    });\n\n    const list = response.results.map((item) => ({\n        title: item.kpmg_title.raw,\n        description: item.kpmg_description.raw,\n        link: item.kpmg_url.raw,\n        pubDate: parseDate(item.kpmg_article_date_time.raw),\n        image: item.kpmg_image.raw,\n        imageAlt: item.kpmg_image_alt?.raw,\n    }));\n\n    const item = await Promise.all(","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/kpmg/insights.tsx#L66-L102","documentation":"Thrown by the KPMG insights route when the :lang path parameter does not match a key in the endpoints map, which only contains 'en' and 'zh'. The route default is 'en', so this only fires when a user explicitly supplies an unsupported language code.","triggerScenarios":"Calling /kpmg/insights/ja, /kpmg/insights/fr, or any lang value other than 'en'/'zh'. Also fires for case mismatches like 'EN' or 'Zh' since the lookup is case-sensitive with no normalization.","commonSituations":"User assumes more languages are supported (KPMG has many regional sites). User passes an uppercase or mixed-case code. A typo in the URL. The route needs a new language but the endpoints map and this check were not updated together.","solutions":["Use only 'en' or 'zh' — these are the two configured endpoints.","Normalize the input with lang.toLowerCase() before lookup to handle case-insensitive input.","Include the valid options in the error message: throw new InvalidParameterError(`Invalid language '${lang}'. Supported: en, zh`).","To add a language, add an entry to the endpoints object with title/link/api and it will be automatically accepted."],"exampleFix":"// before\nconst { lang = 'en' } = ctx.req.param();\nconst endpoint = endpoints[lang];\nif (!endpoint) throw new InvalidParameterError('Invalid language');\n\n// after — case-insensitive + helpful message\nconst { lang = 'en' } = ctx.req.param();\nconst normalized = lang.toLowerCase();\nconst endpoint = endpoints[normalized as keyof typeof endpoints];\nif (!endpoint) {\n    throw new InvalidParameterError(`Invalid language '${lang}'. Supported: ${Object.keys(endpoints).join(', ')}`);\n}","handlingStrategy":"validation","validationCode":"const validLangs = Object.keys(endpoints); // ['en', 'zh']\nconst { lang = 'en' } = ctx.req.param();\nconst normalized = lang.toLowerCase();\nif (!validLangs.includes(normalized)) {\n    throw new InvalidParameterError(`Invalid language '${lang}'. Supported: ${validLangs.join(', ')}`);\n}","typeGuard":"function isKpmgLang(lang: string): lang is keyof typeof endpoints {\n    return lang in endpoints;\n}","tryCatchPattern":null,"preventionTips":["Normalize case with toLowerCase() before lookup.","Derive valid values from the endpoints object keys to keep docs and validation in sync.","Include the supported list in the error message.","When adding a language, add the endpoint entry — the check auto-accepts it."],"tags":["validation","language","parameter","kpmg","case-sensitivity"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}