diff --git a/Sources/ZcashLightClientKit/Extensions/SynchronizerError+LocalizedError.swift b/Sources/ZcashLightClientKit/Extensions/SynchronizerError+LocalizedError.swift new file mode 100644 index 00000000..0eaaf4cb --- /dev/null +++ b/Sources/ZcashLightClientKit/Extensions/SynchronizerError+LocalizedError.swift @@ -0,0 +1,45 @@ +// +// SynchronizerError+LocalizedError.swift +// +// +// Created by Francisco Gindre on 7/11/22. +// + +import Foundation + +extension SynchronizerError: LocalizedError { + public var errorDescription: String? { + switch self { + case .initFailed(message: let message): + return "Failed to initialize. Message: \(message)" + case .notPrepared: + return "Synchronizer is not prepared. run `prepare()` before `start()" + case .syncFailed: + return "Synchronizer failed" + case .connectionFailed(message: let message): + return "Connection Failed. Error: \(message)" + case .generalError(message: let message): + return "An error ocurred when syncing. Message: \(message)" + case .maxRetryAttemptsReached(attempts: let attempts): + return "An error occured. We made \(attempts) retry attempts." + case .connectionError(status: let status, message: let message): + return "There's a connection error. Status #\(status). Message: \(message)" + case .networkTimeout: + return "Network Timeout. Please check Internet connection" + case .uncategorized(underlyingError: let underlyingError): + return "Uncategorized Error. Underlying Error: \(underlyingError)" + case .criticalError: + return "A critical Error Ocurred" + case .parameterMissing(underlyingError: let underlyingError): + return "Sapling parameters are not present or couldn't be downloaded. Error: \(underlyingError)." + case .rewindError(underlyingError: let underlyingError): + return "Error when rescanning. Error: \(underlyingError)" + case .rewindErrorUnknownArchorHeight: + return "Error when rescanning. We couldn't find a point in time to rewing. Please attempt a full re-scan" + case .invalidAccount: + return "We couldn't find this account number." + case .lightwalletdValidationFailed(underlyingError: let underlyingError): + return "We connected to the network but we couldn't verify the server. `lightwalletdValidationFailed` error: \(underlyingError)." + } + } +} diff --git a/Sources/ZcashLightClientKit/Synchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer.swift index a9fa8588..67f11235 100644 --- a/Sources/ZcashLightClientKit/Synchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer.swift @@ -11,21 +11,21 @@ import Foundation /// Represents errors thrown by a Synchronizer public enum SynchronizerError: Error { - case initFailed(message: String) - case notPrepared - case syncFailed - case connectionFailed(message: Error) - case generalError(message: String) - case maxRetryAttemptsReached(attempts: Int) - case connectionError(status: Int, message: String) - case networkTimeout - case uncategorized(underlyingError: Error) - case criticalError - case parameterMissing(underlyingError: Error) - case rewindError(underlyingError: Error) - case rewindErrorUnknownArchorHeight - case invalidAccount - case lightwalletdValidationFailed(underlyingError: Error) + case initFailed(message: String) // ZcashLightClientKit.SynchronizerError error 0. + case notPrepared // ZcashLightClientKit.SynchronizerError error 9. + case syncFailed // ZcashLightClientKit.SynchronizerError error 10. + case connectionFailed(message: Error) // ZcashLightClientKit.SynchronizerError error 1. + case generalError(message: String) // ZcashLightClientKit.SynchronizerError error 2. + case maxRetryAttemptsReached(attempts: Int) // ZcashLightClientKit.SynchronizerError error 3. + case connectionError(status: Int, message: String) // ZcashLightClientKit.SynchronizerError error 4. + case networkTimeout // ZcashLightClientKit.SynchronizerError error 11. + case uncategorized(underlyingError: Error) // ZcashLightClientKit.SynchronizerError error 5. + case criticalError // ZcashLightClientKit.SynchronizerError error 12. + case parameterMissing(underlyingError: Error) // ZcashLightClientKit.SynchronizerError error 6. + case rewindError(underlyingError: Error) // ZcashLightClientKit.SynchronizerError error 7. + case rewindErrorUnknownArchorHeight // ZcashLightClientKit.SynchronizerError error 13. + case invalidAccount // ZcashLightClientKit.SynchronizerError error 14. + case lightwalletdValidationFailed(underlyingError: Error) // ZcashLightClientKit.SynchronizerError error 8. } public enum ShieldFundsError: Error { diff --git a/Tests/OfflineTests/ErrorLocalizationTests.swift b/Tests/OfflineTests/ErrorLocalizationTests.swift new file mode 100644 index 00000000..6ea17cd5 --- /dev/null +++ b/Tests/OfflineTests/ErrorLocalizationTests.swift @@ -0,0 +1,17 @@ +// +// ErrorLocalizationTests.swift +// +// +// Created by Francisco Gindre on 7/11/22. +// + +import XCTest +import ZcashLightClientKit +class ErrorLocalizationTests: XCTestCase { + + func testLocalizedError() throws { + let sychronizerError = SynchronizerError.networkTimeout as Error + XCTAssertEqual(sychronizerError.localizedDescription, "Network Timeout. Please check Internet connection") + } + +}