[#1035] Create ZcashError.unknown

- new ZcashError.unknown that wraps and handles any Error added

[#1035] Create ZcashError.unknown (#1036)

- improved the conversion of error -> ZcashError

[#1035] Create ZcashError.unknown (#1036)

- detailed comments of the unknown case
This commit is contained in:
Lukas Korba 2023-05-09 13:31:05 +02:00
parent 336c5a7c38
commit 9c611b31e3
4 changed files with 32 additions and 0 deletions

View File

@ -11,6 +11,10 @@ error originates. And it can help with debugging.
import Foundation
public enum ZcashError: Equatable, Error {
/// Some error happened that is not handled as `ZcashError`.
/// Use case is to map `any Error`(in the apps for example) to this one so it can be assured only `ZcashError` is floating through apps.
/// ZUNKWN0001
case unknown(_ error: Error)
/// Updating of paths in `Initilizer` according to alias failed.
/// ZINIT0001
case initializerCantUpdateURLWithAlias(_ url: URL)
@ -505,6 +509,7 @@ public enum ZcashError: Equatable, Error {
public var message: String {
switch self {
case .unknown: return "Some error happened that is not handled as `ZcashError`."
case .initializerCantUpdateURLWithAlias: return "Updating of paths in `Initilizer` according to alias failed."
case .initializerAliasAlreadyInUse: return "Alias used to create this instance of the `SDKSynchronizer` is already used by other instance."
case .serviceUnknownError: return "Unknown GRPC Service error"
@ -655,6 +660,7 @@ public enum ZcashError: Equatable, Error {
public var code: ZcashErrorCode {
switch self {
case .unknown: return .unknown
case .initializerCantUpdateURLWithAlias: return .initializerCantUpdateURLWithAlias
case .initializerAliasAlreadyInUse: return .initializerAliasAlreadyInUse
case .serviceUnknownError: return .serviceUnknownError

View File

@ -9,6 +9,8 @@ error originates. And it can help with debugging.
*/
public enum ZcashErrorCode: String {
/// Some error happened that is not handled as `ZcashError`.
case unknown = "ZUNKWN0001"
/// Updating of paths in `Initilizer` according to alias failed.
case initializerCantUpdateURLWithAlias = "ZINIT0001"
/// Alias used to create this instance of the `SDKSynchronizer` is already used by other instance.

View File

@ -24,6 +24,12 @@ import Foundation
*/
enum ZcashErrorDefinition {
/// Some error happened that is not handled as `ZcashError`. All errors in the SDK are (should be) `ZcashError`.
/// This case is ideally not contructed directly or thrown by any SDK function, rather it's a wrapper for case clients expect ZcashErrot and want to pass it to a function/enum.
/// If this is the case, use `toZcashError()` extension of Error. This helper avoids to end up with Optional handling.
// sourcery: code="ZUNKWN0001"
case unknown(_ error: Error)
// MARK: - Initializer
/// Updating of paths in `Initilizer` according to alias failed.

View File

@ -0,0 +1,18 @@
//
// Error+ZcashError.swift
//
//
// Created by Lukáš Korba on 09.05.2023.
//
import Foundation
public extension Error {
func toZcashError() -> ZcashError {
if let zcashError = self as? ZcashError {
return zcashError
} else {
return ZcashError.unknown(self)
}
}
}