{"record":{"id":"b53e983069d8bdb8","repo":"LykosAI/StabilityMatrix","slug":"resources-validation-apikeyrequired","errorCode":null,"errorMessage":"Resources.Validation_ApiKeyRequired","messagePattern":"Resources\\.Validation_ApiKeyRequired","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"warning","filePath":"StabilityMatrix.Avalonia/ViewModels/Settings/AccountSettingsViewModel.cs","lineNumber":652,"sourceCode":"    {\n        HasGeminiApiKey = value.IsConnected;\n    }\n\n    [RelayCommand]\n    private async Task SetGeminiApiKey()\n    {\n        if (!await BeforeConnectCheck())\n            return;\n\n        var field = new TextBoxField\n        {\n            Label = Resources.Label_GeminiApiKey,\n            IsPassword = true,\n            Validator = s =>\n            {\n                if (string.IsNullOrWhiteSpace(s))\n                {\n                    throw new ValidationException(Resources.Validation_ApiKeyRequired);\n                }\n            },\n        };\n\n        var dialog = DialogHelper.CreateTextEntryDialog(\n            Resources.Label_SetGeminiApiKey,\n            Resources.Text_SetGeminiApiKeyDescription,\n            null,\n            [field]\n        );\n        dialog.PrimaryButtonText = Resources.Action_Save;\n\n        if (await dialog.ShowAsync() != ContentDialogResult.Primary || field.Text is not { } apiKey)\n        {\n            return;\n        }\n\n        await accountsService.GeminiLoginAsync(apiKey);","sourceCodeStart":634,"sourceCodeEnd":670,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/ViewModels/Settings/AccountSettingsViewModel.cs#L634-L670","documentation":"The Gemini API key dialog in AccountSettingsViewModel validates input with ValidationException(Resources.Validation_ApiKeyRequired), thrown when the key is null or whitespace. The message text is the localized resource string named Validation_ApiKeyRequired, so the runtime message is the localized 'API key required' text rather than the literal resource name.","triggerScenarios":"Submitting the 'Set Gemini API key' dialog (AccountSettingsViewModel.cs:652) with an empty or whitespace-only key.","commonSituations":"User has not obtained a Google AI Studio API key; paste failed or pasted only spaces; masked password field hides emptiness; missing/older resource assembly yields an unexpected message text.","solutions":["Obtain a Gemini API key from Google AI Studio and paste it into the field before confirming.","Trim whitespace around the pasted key.","If the message shows the raw resource name, refresh/repair the localized Resources files so Validation_ApiKeyRequired resolves."],"exampleFix":"// before\nthrow new ValidationException(Resources.Validation_ApiKeyRequired);\n// after\nthrow new ValidationException(string.IsNullOrWhiteSpace(Resources.Validation_ApiKeyRequired)\n    ? \"API key is required\" : Resources.Validation_ApiKeyRequired);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(geminiKey)) {\n    // get a key from Google AI Studio before opening the dialog\n    return;\n}","typeGuard":"bool HasGeminiKey(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { await ShowGeminiKeyDialog(); }\ncatch (ValidationException ex) { ShowStatus(ex.Message); }","preventionTips":["Create a Gemini API key at Google AI Studio before connecting.","Trim pasted keys to avoid whitespace-only submissions.","Ensure Resources resource files are present so the localized message resolves instead of a raw resource name."],"tags":["validation","api-key","localization"],"backgroundTag":"missing-api-key","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}