From 336dd1441b9b77b7d21aea68b76f588a99812fa0 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Tue, 6 Jan 2026 14:02:40 +0545 Subject: [PATCH] Fix ignored keychain save result to prevent creating custom models without API keys --- .../Views/AI Models/AddCustomModelView.swift | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/VoiceInk/Views/AI Models/AddCustomModelView.swift b/VoiceInk/Views/AI Models/AddCustomModelView.swift index c98635b..a78551e 100644 --- a/VoiceInk/Views/AI Models/AddCustomModelView.swift +++ b/VoiceInk/Views/AI Models/AddCustomModelView.swift @@ -235,8 +235,15 @@ struct AddCustomModelCardView: View { modelName: trimmedModelName, isMultilingual: isMultilingual ) - APIKeyManager.shared.saveCustomModelAPIKey(trimmedApiKey, forModelId: editing.id) - customModelManager.updateCustomModel(updatedModel) + + if APIKeyManager.shared.saveCustomModelAPIKey(trimmedApiKey, forModelId: editing.id) { + customModelManager.updateCustomModel(updatedModel) + } else { + validationErrors = ["Failed to securely save API Key to Keychain. Please check your system settings or try again."] + showingAlert = true + isSaving = false + return + } } else { let customModel = CustomCloudModel( name: generatedName, @@ -246,8 +253,15 @@ struct AddCustomModelCardView: View { modelName: trimmedModelName, isMultilingual: isMultilingual ) - APIKeyManager.shared.saveCustomModelAPIKey(trimmedApiKey, forModelId: customModel.id) - customModelManager.addCustomModel(customModel) + + if APIKeyManager.shared.saveCustomModelAPIKey(trimmedApiKey, forModelId: customModel.id) { + customModelManager.addCustomModel(customModel) + } else { + validationErrors = ["Failed to securely save API Key to Keychain. Please check your system settings or try again."] + showingAlert = true + isSaving = false + return + } } onModelAdded()