{"record":{"id":"7eb406a50efe926e","repo":"linshenkx/prompt-optimizer","slug":"unsupported-language-language-7eb406","errorCode":null,"errorMessage":"Unsupported language: ${language}","messagePattern":"Unsupported language: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/mcp-server/src/adapters/language-service.ts","lineNumber":37,"sourceCode":"      'en': 'en-US',\n      'en-US': 'en-US',\n      'english': 'en-US'\n    };\n\n    this.currentLanguage = languageMap[defaultLanguage as keyof typeof languageMap] || 'en-US';\n  }\n\n  async initialize(): Promise<void> {\n    this.initialized = true;\n  }\n\n  async getCurrentLanguage(): Promise<BuiltinTemplateLanguage> {\n    return this.currentLanguage;\n  }\n\n  async setLanguage(language: BuiltinTemplateLanguage): Promise<void> {\n    if (!(await this.isValidLanguage(language))) {\n      throw new Error(`Unsupported language: ${language}`);\n    }\n    this.currentLanguage = language;\n  }\n\n  async toggleLanguage(): Promise<BuiltinTemplateLanguage> {\n    const newLanguage = this.currentLanguage === 'zh-CN' ? 'en-US' : 'zh-CN';\n    await this.setLanguage(newLanguage);\n    return newLanguage;\n  }\n\n  async isValidLanguage(language: string): Promise<boolean> {\n    const supportedLanguages = await this.getSupportedLanguages();\n    return supportedLanguages.includes(language as BuiltinTemplateLanguage);\n  }\n\n  async getSupportedLanguages(): Promise<BuiltinTemplateLanguage[]> {\n    return ['en-US', 'zh-CN'];\n  }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/mcp-server/src/adapters/language-service.ts#L19-L55","documentation":"Thrown by LanguageService.setLanguage when the passed language is not one of the supported built-in template languages. Validation is done via isValidLanguage(), so any string outside the built-in set (currently 'zh-CN' and 'en-US') is rejected before assignment.","triggerScenarios":"Calling setLanguage('zh_CN'), setLanguage('en'), setLanguage('fr-FR'), or any string not returned by the built-in language list; also calling toggleLanguage's underlying setLanguage with a value sourced from an unvalidated config or env var.","commonSituations":"Hardcoding a locale with the wrong format (underscore vs hyphen, missing region); passing a user's OS locale directly (navigator.language) without mapping it; adding a new language to config but not to the built-in template set.","solutions":["Use only 'zh-CN' or 'en-US' — check the BowerTemplateLanguage/BuiltinTemplateLanguage type or listSupportedLanguages() for the exact set","Map arbitrary user locales to the nearest supported one before calling setLanguage","If you need another language, extend the built-in templates rather than passing an ad-hoc string"],"exampleFix":"// before\nawait svc.setLanguage(userLocale); // e.g. 'zh_CN' or 'fr-FR'\n\n// after\nconst supported = ['zh-CN', 'en-US'] as const;\nconst lang = supported.includes(userLocale as any)\n  ? (userLocale as typeof supported[number])\n  : userLocale.startsWith('zh') ? 'zh-CN' : 'en-US';\nawait svc.setLanguage(lang);","handlingStrategy":"type-guard","validationCode":"const SUPPORTED = ['zh-CN', 'en-US'] as const;\nconst lang = SUPPORTED.includes(reqLang as any) ? reqLang : 'en-US';\nawait svc.setLanguage(lang);","typeGuard":"const isBuiltinLanguage = (l: string): l is 'zh-CN' | 'en-US' =>\n  l === 'zh-CN' || l === 'en-US';","tryCatchPattern":"try { await svc.setLanguage(lang); } catch { await svc.setLanguage('en-US'); }","preventionTips":["Type the variable as BuiltinTemplateLanguage so invalid values fail at compile time","Map user locales to the supported set at the system boundary"],"tags":["i18n","validation","language","mcp-server"],"backgroundTag":"unsupported-enum-value","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}