From df1c0d31cbc463080f1025ceaa8cd93388147b68 Mon Sep 17 00:00:00 2001 From: benk10 Date: Tue, 27 Jan 2026 19:11:30 -0600 Subject: [PATCH 1/2] fix: add LocalizedError conformance for readable error messages Custom error enums (CustomServiceError, KeychainError) now conform to LocalizedError and provide human-readable errorDescription. Previously, these errors displayed as "The operation couldn't be completed. (Bitkit.CustomServiceError error 1.)" which was not helpful to users. --- Bitkit/Utilities/Errors.swift | 44 +++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Bitkit/Utilities/Errors.swift b/Bitkit/Utilities/Errors.swift index 410ea547..b1301a7b 100644 --- a/Bitkit/Utilities/Errors.swift +++ b/Bitkit/Utilities/Errors.swift @@ -1,7 +1,7 @@ import Foundation import LDKNode -enum CustomServiceError: Error { +enum CustomServiceError: LocalizedError { case nodeNotSetup case nodeNotStarted case onchainWalletNotInitialized @@ -12,14 +12,54 @@ enum CustomServiceError: Error { case regtestOnlyMethod case channelSizeExceedsMaximum case currencyRateUnavailable + + var errorDescription: String? { + switch self { + case .nodeNotSetup: + return "Node is not setup" + case .nodeNotStarted: + return "Node is not started" + case .onchainWalletNotInitialized: + return "Onchain wallet not created" + case .mnemonicNotFound: + return "Mnemonic not found" + case .nodeStillRunning: + return "Node is still running" + case .onchainWalletStillRunning: + return "Onchain wallet is still running" + case .invalidNodeSigningMessage: + return "Invalid node signing message" + case .regtestOnlyMethod: + return "Method only available in regtest environment" + case .channelSizeExceedsMaximum: + return "Channel size exceeds maximum allowed size" + case .currencyRateUnavailable: + return "Currency rate unavailable" + } + } } -enum KeychainError: Error { +enum KeychainError: LocalizedError { case failedToSave case failedToSaveAlreadyExists case failedToDelete case failedToLoad case keychainWipeNotAllowed + + var errorDescription: String? { + switch self { + case .failedToSave: + return "Failed to save to keychain" + case .failedToSaveAlreadyExists: + return "Failed to save to keychain: item already exists" + case .failedToDelete: + return "Failed to delete from keychain" + case .failedToLoad: + return "Failed to load from keychain" + case .keychainWipeNotAllowed: + return "Keychain wipe not allowed" + } + } } enum BlocktankError_deprecated: Error { From 9e1f024d091f6940c257995ce6405b5c72e8d0fe Mon Sep 17 00:00:00 2001 From: benk10 Date: Tue, 27 Jan 2026 21:07:01 -0600 Subject: [PATCH 2/2] fix: suppress CancellationError in error toasts CancellationError is thrown when tasks are cancelled (e.g., user navigates away during sync). This is expected behavior and shouldn't show an error toast to the user. --- Bitkit/ViewModels/AppViewModel.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Bitkit/ViewModels/AppViewModel.swift b/Bitkit/ViewModels/AppViewModel.swift index 3fbaf910..a71f618f 100644 --- a/Bitkit/ViewModels/AppViewModel.swift +++ b/Bitkit/ViewModels/AppViewModel.swift @@ -216,6 +216,9 @@ extension AppViewModel { } func toast(_ error: Error) { + if error is CancellationError { + return + } toast(type: .error, title: "Error", description: error.localizedDescription) }