{"record":{"id":"f2d9b5852e2a353b","repo":"mudler/LocalAI","slug":"invalid-language-s-available-v","errorCode":null,"errorMessage":"Invalid language: %s. Available: %v","messagePattern":"Invalid language: (.+?)\\. Available: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/supertonic/helper.go","lineNumber":438,"sourceCode":"\tfor strings.Contains(text, \"``\") {\n\t\ttext = strings.ReplaceAll(text, \"``\", \"`\")\n\t}\n\n\t// Remove extra spaces\n\ttext = regexp.MustCompile(`\\s+`).ReplaceAllString(text, \" \")\n\ttext = strings.TrimSpace(text)\n\n\t// If text doesn't end with punctuation, quotes, or closing brackets, add a period\n\tif text != \"\" {\n\t\tendsWithPunct := regexp.MustCompile(`[.!?;:,'\"\\x{201C}\\x{201D}\\x{2018}\\x{2019})\\]}…。」』】〉》›»]$`)\n\t\tif !endsWithPunct.MatchString(text) {\n\t\t\ttext += \".\"\n\t\t}\n\t}\n\n\t// Validate language\n\tif !isValidLang(lang) {\n\t\tpanic(fmt.Sprintf(\"Invalid language: %s. Available: %v\", lang, AvailableLangs))\n\t}\n\n\t// Wrap text with language tags\n\ttext = fmt.Sprintf(\"<%s>%s</%s>\", lang, text, lang)\n\n\treturn text\n}\n\nfunc lengthToMask(lengths []int64, maxLen int) [][][]float64 {\n\tbsz := len(lengths)\n\tmask := make([][][]float64, bsz)\n\n\tfor i := 0; i < bsz; i++ {\n\t\trow := make([]float64, maxLen)\n\t\tfor j := 0; j < maxLen; j++ {\n\t\t\tif int64(j) < lengths[i] {\n\t\t\t\trow[j] = 1.0\n\t\t\t} else {","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/supertonic/helper.go#L420-L456","documentation":"Panic thrown in supertonic's helper.go text-preparation path when the language tag passed to the wrapping routine is not in AvailableLangs (a fixed list of 32 codes: en, ko, ja, ar, bg, cs, da, de, el, es, et, fi, fr, hi, hr, hu, id, it, lt, lv, nl, pl, pt, ro, ru, sk, sl, sv, tr, uk, vi, na). The text is wrapped in <lang>...</lang> tags for the multilingual model, so an unknown code cannot be encoded.","triggerScenarios":"Calling the internal text-wrapping helper with a language string outside the list — e.g. 'zh' (Chinese, not supported), 'en-US', 'EN' (case-sensitive), or '' — instead of a bare supported code. Reached when the request/model config supplies a language the list does not contain (backend.go's resolveLang normally validates/falls back first).","commonSituations":"Users configuring supertonic TTS with a BCP-47 style locale instead of the bare code; requesting Chinese which is absent from this model's language set; passing an empty language from a config with a missing lang field; direct Go API use bypassing resolveLang's fallback.","solutions":["Use one of the 32 supported bare codes from the error message (e.g. 'en', 'ko', 'ja')","Strip region subtags: 'en-US' -> 'en'","Leave language unset so backend.go resolveLang applies its default/fallback instead of panicking","If you need an unsupported language, use a different TTS backend/model that covers it"],"exampleFix":"# before\nlang: \"en-US\"\n# after\nlang: \"en\"","handlingStrategy":"type-guard","validationCode":"var available = map[string]bool{} // fill from supertonic.AvailableLangs\nfor _, l := range supertonic.AvailableLangs { available[l] = true }\nif !available[lang] { lang = \"en\" }","typeGuard":"func isValidSupertonicLang(lang string) bool {\n    for _, l := range supertonic.AvailableLangs {\n        if l == lang { return true }\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Normalize user locales to bare codes before passing them down","Rely on backend.go resolveLang to validate and fall back instead of calling the helper directly","Offer a UI dropdown restricted to the 32 supported languages"],"tags":["tts","supertonic","language","validation","config"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}