Merge pull request #1036 from LukasKorba/1035-Create-ZcashError.unknown

- new ZcashError.unknown that wraps and handles any Error addedCreate ZcashError.unknown
This commit is contained in:
Lukas Korba 2023-05-10 14:49:03 +02:00 committed by GitHub
commit 355a3fc4f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
@ -508,6 +512,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"
@ -659,6 +664,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)
}
}
}