[#392] Synchronizer error 8. when syncing. (#413)

Closes #392

This commit localizes SynchronizerError to better support Error messages
This commit is contained in:
Francisco Gindre 2022-07-12 17:28:16 -03:00 committed by GitHub
parent 2fcfa6fdbe
commit e131ccbd07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 15 deletions

View File

@ -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)."
}
}
}

View File

@ -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 {

View File

@ -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")
}
}