{"record":{"id":"64006ebc8c120875","repo":"babalae/better-genshin-impact","slug":"ui","errorCode":null,"errorMessage":"当前UI语言为空，无法更新语言文件。","messagePattern":"当前UI语言为空，无法更新语言文件。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs","lineNumber":108,"sourceCode":"    public AllConfig Config { get; set; }\n    public ObservableCollection<OverlayMetricSettingItem> OverlayMetricItems { get; }\n    public ObservableCollection<OverlayStyleSettingGroup> OverlayStyleSettingGroups { get; }\n    public ObservableCollection<string> CountryList { get; } = new();\n    public ObservableCollection<string> Areas { get; } = new();\n\n    public ObservableCollection<string> MapPathingTypes { get; } = [\"SIFT\", \"TemplateMatch\"];\n\n    [ObservableProperty] private FrozenDictionary<string, string> _languageDict =\n        new[] { \"zh-Hans\", \"zh-Hant\", \"en\", \"ja\" }\n            .ToFrozenDictionary(c => c, c => CultureInfoNameToKVPConverter.GetDisplayName(c));\n\n    [RelayCommand]\n    private async Task OnUpdateUiLanguageAsync()\n    {\n        var cultureName = Config.OtherConfig.UiCultureInfoName ?? string.Empty;\n        if (string.IsNullOrWhiteSpace(cultureName))\n        {\n            throw new InvalidOperationException(\"当前UI语言为空，无法更新语言文件。\");\n        }\n\n        if (cultureName == \"zh-Hans\")\n        {\n            await ThemedMessageBox.InformationAsync(\"zh-Hans 无语言文件，无需更新。\");\n            return;\n        }\n\n        var urls = new[]\n        {\n            $\"https://raw.githubusercontent.com/babalae/bettergi-i18n/refs/heads/main/i18n/{cultureName}.json\",\n            $\"https://cnb.cool/bettergi/bettergi-i18n/-/git/raw/main/i18n/{cultureName}.json\"\n        };\n\n        using var httpClient = new HttpClient\n        {\n            Timeout = TimeSpan.FromSeconds(30)\n        };","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs#L90-L126","documentation":"Thrown by OnUpdateUiLanguageAsync when Config.OtherConfig.UiCultureInfoName is null, empty, or whitespace. The culture name is used to build the remote i18n JSON filename, so a blank value cannot map to a downloadable language file. The code treats this as a programmer/state error (InvalidOperationException) rather than prompting the user.","triggerScenarios":"Invoking the 'update language file' command while UiCultureInfoName is unset. Occurs when the config was never initialized, a config migration left it blank, or the settings dropdown was cleared and saved as empty.","commonSituations":"Fresh install before any language is selected; manually edited config.json with the field removed or blanked; a culture dropdown cleared by the user; config load fell back to a default that leaves the field null.","solutions":["Default the language dropdown to zh-Hans in the settings UI so UiCultureInfoName is never blank.","Validate UiCultureInfoName before invoking the command and show ThemedMessageBox.WarningAsync instead of throwing.","Ensure Config.OtherConfig initializes UiCultureInfoName to a non-empty fallback (e.g. zh-Hans)."],"exampleFix":"// before\nvar cultureName = Config.OtherConfig.UiCultureInfoName ?? string.Empty;\nif (string.IsNullOrWhiteSpace(cultureName))\n{\n    throw new InvalidOperationException(\"当前UI语言为空，无法更新语言文件。\");\n}\n\n// after\nvar cultureName = Config.OtherConfig.UiCultureInfoName ?? string.Empty;\nif (string.IsNullOrWhiteSpace(cultureName))\n{\n    await ThemedMessageBox.WarningAsync(\"请先在设置中选择 UI 语言。\");\n    return;\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(Config.OtherConfig.UiCultureInfoName))\n{\n    // Do not invoke OnUpdateUiLanguage; prompt the user to pick a language first.\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default UiCultureInfoName to zh-Hans in the config model so it is never null.","Disable the 'update language' button in the UI when no language is selected.","Treat a blank culture as a user-facing warning, not an exceptional state."],"tags":["config","i18n","validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}