Update error type implementation so handling them is less fragile #6498

pull/6520/head
Krypto Pank 2 years ago
parent 7c4e835add
commit cc855861d0
  1. 2
      AlphaWallet/Browser/Coordinators/DappBrowserCoordinator.swift
  2. 2
      AlphaWallet/Common/Coordinators/WalletApiCoordinator.swift
  3. 83
      AlphaWallet/Common/Types/Error.swift
  4. 6
      AlphaWallet/Extensions/UIViewController.swift
  5. 2
      AlphaWallet/Settings/Coordinators/CheckTransactionStateCoordinator.swift
  6. 2
      AlphaWallet/Settings/Coordinators/PingInfuraCoordinator.swift
  7. 11
      AlphaWallet/Settings/ViewModels/CheckTransactionStateViewModel.swift
  8. 2
      AlphaWallet/Settings/ViewModels/ExportJsonKeystoreFileViewModel.swift
  9. 6
      AlphaWallet/Swap/Swap/SwapTokensCoordinator.swift
  10. 2
      AlphaWallet/Swap/Swap/ViewModels/SwapQuoteDetailsViewModel.swift
  11. 4
      AlphaWallet/Tokens/Coordinators/ClaimPaidOrderCoordinator.swift
  12. 4
      AlphaWallet/Tokens/ViewControllers/NewTokenViewController.swift
  13. 2
      AlphaWallet/Transactions/Coordinators/ReplaceTransactionCoordinator.swift
  14. 4
      AlphaWallet/Transfer/Collectibles/Coordinators/TransferCollectiblesCoordinator.swift
  15. 4
      AlphaWallet/Transfer/Collectibles/ViewControllers/SendSemiFungibleTokenViewController.swift
  16. 22
      AlphaWallet/Transfer/Collectibles/ViewModels/SendSemiFungibleTokenViewModel.swift
  17. 2
      AlphaWallet/Transfer/Coordinators/SendCoordinator.swift
  18. 4
      AlphaWallet/Transfer/Coordinators/SignMessageCoordinator.swift
  19. 4
      AlphaWallet/Transfer/Coordinators/TokenScriptCoordinator.swift
  20. 4
      AlphaWallet/Transfer/Coordinators/TransferNFTCoordinator.swift
  21. 2
      AlphaWallet/Transfer/ViewControllers/SendViewController.swift
  22. 4
      AlphaWallet/Transfer/ViewModels/SendTransactionErrorViewModel.swift
  23. 4
      AlphaWallet/Transfer/ViewModels/SendViewModel.swift
  24. 6
      AlphaWallet/Transfer/ViewModels/TransactionConfirmation/CancelTransactionViewModel.swift
  25. 2
      AlphaWallet/Wallet/ViewControllers/ImportWalletViewController.swift
  26. 2
      AlphaWallet/WalletConnect/CAIP10AccountProvidable.swift
  27. 2
      AlphaWallet/WalletConnect/Coordinator/WalletConnectCoordinator.swift
  28. 6
      AlphaWallet/WalletConnect/WalletConnectServer.swift
  29. 2
      AlphaWalletTests/Common/Types/ErrorTests.swift
  30. 16
      AlphaWalletTests/EtherClient/EtherKeystoreTests.swift
  31. 2
      modules/AlphaWalletFoundation/AlphaWalletFoundation/EtherClient/CastError.swift
  32. 2
      modules/AlphaWalletFoundation/AlphaWalletFoundation/EtherClient/KeyStoreError.swift
  33. 4
      modules/AlphaWalletFoundation/AlphaWalletFoundation/SwapToken/NativeSwap/Types/SwapError.swift
  34. 2
      modules/AlphaWalletFoundation/AlphaWalletFoundation/TokenScriptClient/Models/FunctionOrigin.swift
  35. 22
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/Logic/GetBlockTimestamp.swift
  36. 4
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Transfer/TransactionConfigurator.swift
  37. 2
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Transfer/Types/SendTransactionError.swift
  38. 8
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Types/AppErrors.swift
  39. 6
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Types/RpcJson/JsonRpcError.swift

@ -872,7 +872,7 @@ extension DappBrowserCoordinator {
enum DappBrowserError: Error, LocalizedError {
case serverUnavailable
var localizedDescription: String {
var errorDescription: String? {
return "RPC Server Unavailable"
}
}

@ -107,7 +107,7 @@ class WalletApiCoordinator: NSObject, Coordinator {
private func displayError(_ error: Error, completion: @escaping () -> Void) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError, completion: completion)
.displayError(message: error.localizedDescription, completion: completion)
}
private func acceptProposal(proposalType: ProposalType) -> Promise<ProposalResult> {

@ -2,8 +2,9 @@
import Foundation
import AlphaWalletFoundation
import AlphaWalletCore
extension KeystoreError {
extension KeystoreError: LocalizedError {
public var errorDescription: String? {
switch self {
case .failedToDeleteAccount:
@ -40,69 +41,41 @@ extension KeystoreError {
}
}
public struct UndefinedError: LocalizedError { }
public struct UnknownError: LocalizedError { }
extension Error {
public var prettyError: String {
//TODO figure out how we can remove this switch-cases. Too fragile
switch self {
case let error as BuyCryptoError:
return error.localizedDescription
case let error as ActiveWalletError:
return error.localizedDescription
case let error as SwapTokenError:
return error.localizedDescription
case let error as WalletApiError:
return error.localizedDescription
case let error as FunctionError:
return error.localizedDescription
case let error as TransactionConfiguratorError:
return error.localizedDescription
case let error as KeystoreError:
return error.errorDescription ?? UnknownError().localizedDescription
case let error as SendInputErrors:
return error.errorDescription ?? UnknownError().localizedDescription
case let error as RpcNodeRetryableRequestError:
return error.errorDescription ?? UnknownError().localizedDescription
case let error as OpenURLError:
return error.localizedDescription
case let error as ConfigureTransactionError:
return error.localizedDescription
case let error as AddCustomChainError:
return error.localizedDescription
case let error as SignMessageValidatorError:
return error.localizedDescription
case let error as SessionTaskError:
return generatePrettyError(forSessionTaskError: error)
case let error as LocalizedError:
return error.errorDescription ?? UnknownError().localizedDescription
case let error as NSError:
return error.localizedDescription
default:
return UndefinedError().localizedDescription
}
}
public var code: Int { return (self as NSError).code }
public var domain: String { return (self as NSError).domain }
}
private func generatePrettyError(forSessionTaskError error: SessionTaskError) -> String {
switch error {
extension PromiseError: LocalizedError {
public var errorDescription: String? {
return embedded.localizedDescription
}
}
extension SessionTaskError: LocalizedError {
public var errorDescription: String? {
switch self {
case .connectionError(let error):
return error.prettyError
return error.localizedDescription
case .requestError(let error):
return error.prettyError
return error.localizedDescription
case .responseError(let error):
guard let JSONError = error as? JSONRPCError else {
return error.prettyError
return error.localizedDescription
}
switch JSONError {
case .responseError(_, let message, _):
return message
case .responseNotFound, .resultObjectParseError, .errorObjectParseError, .unsupportedVersion, .unexpectedTypeObject, .missingBothResultAndError, .nonArrayResponse:
return UndefinedError().localizedDescription
}
}
extension AnyCAIP10AccountProvidable.CAIP10AccountProvidableError: LocalizedError {
var errorDescription: String? {
switch self {
case .unavailableToBuildBlockchain:
return "Unavailable To Build Blockchain"
case .accountsNotFound:
return "Accounts Not Found"
case .emptyNamespaces:
return "Empty Namespaces"
case .eip155NotFound:
return "Eip155 Not Found"
}
}
}

@ -8,7 +8,7 @@ import SafariServices
import UIKit
import AlphaWalletFoundation
enum ConfirmationError: LocalizedError {
enum ConfirmationError: Error {
case cancel
}
@ -55,10 +55,10 @@ extension UIViewController {
var title = title
let message: String
if title.isEmpty {
title = error.prettyError
title = error.localizedDescription
message = ""
} else {
message = error.prettyError
message = error.localizedDescription
}
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.popoverPresentationController?.sourceView = view

@ -60,7 +60,7 @@ extension CheckTransactionStateCoordinator: SelectTransactionHashViewControllerD
.transactionsState(hash: transactionHash)
.sink(receiveCompletion: { result in
if case .failure(let error) = result {
self.displayErrorMessage(R.string.localizable.checkTransactionStateError(error.prettyError), title: R.string.localizable.error())
self.displayErrorMessage(R.string.localizable.checkTransactionStateError(error.localizedDescription), title: R.string.localizable.error())
}
self.rootViewController.set(isActionButtonEnable: true)

@ -57,7 +57,7 @@ class PingInfuraCoordinator: Coordinator {
if case .failure(let error) = result {
UIAlertController.alert(
title: R.string.localizable.settingsPingInfuraFail(),
message: "\(error.prettyError)",
message: "\(error.localizedDescription)",
alertButtonTitles: [R.string.localizable.oK()],
alertButtonStyles: [.cancel],
viewController: self.viewController,

@ -68,14 +68,3 @@ extension AlphaWalletWeb3.Web3Error: LocalizedError {
}
}
}
extension UndefinedError {
public var localizedDescription: String {
R.string.localizable.undefinedError()
}
}
extension UnknownError {
public var localizedDescription: String {
R.string.localizable.unknownError()
}
}

@ -57,7 +57,7 @@ class ExportJsonKeystoreFileViewModel {
.share()
.eraseToAnyPublisher()
let error = Publishers.Merge(makeJsonFile.compactMap { $0.error?.prettyError }, computeJson.compactMap { $0.error?.prettyError })
let error = Publishers.Merge(makeJsonFile.compactMap { $0.error?.localizedDescription }, computeJson.compactMap { $0.error?.localizedDescription })
.eraseToAnyPublisher()
let fileUrl = makeJsonFile.compactMap { $0.value }

@ -205,7 +205,7 @@ extension SwapTokensCoordinator: ApproveSwapProviderDelegate {
} else {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
}
@ -281,7 +281,7 @@ extension SwapTokensCoordinator: ApproveSwapProviderDelegate {
private func showError(_ error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
}
@ -313,7 +313,7 @@ extension SwapTokensCoordinator: TransactionConfirmationCoordinatorDelegate {
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didFailTransaction error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
func didClose(in coordinator: TransactionConfirmationCoordinator) {

@ -128,7 +128,7 @@ final class SwapQuoteDetailsViewModel {
}
extension TokenLevelTokenScriptDisplayStatus.SignatureValidationError {
var localizedDescription: String {
var errorDescription: String? {
switch self {
case .tokenScriptType1SupportedNotCanonicalizedAndUnsigned:
return R.string.localizable.tokenScriptType1SupportedNotCanonicalizedAndUnsigned()

@ -86,7 +86,7 @@ class ClaimPaidOrderCoordinator: Coordinator {
} catch {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
}
}
@ -95,7 +95,7 @@ extension ClaimPaidOrderCoordinator: TransactionConfirmationCoordinatorDelegate
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didFailTransaction error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
delegate?.coordinator(self, didFailTransaction: error)
}

@ -318,7 +318,7 @@ class NewTokenViewController: UIViewController {
var balance: [String] = viewModel.erc875TokenBalance
guard let address = AlphaWallet.Address(string: contract) else {
addressTextField.errorState = .error(InputError.invalidAddress.prettyError)
addressTextField.errorState = .error(InputError.invalidAddress.localizedDescription)
return
}
addressTextField.errorState = .none
@ -378,7 +378,7 @@ extension NewTokenViewController: AddressTextFieldDelegate {
}
func displayError(error: Error, for textField: AddressTextField) {
textField.errorState = .error(error.prettyError)
textField.errorState = .error(error.localizedDescription)
}
func openQRCodeReader(for textField: AddressTextField) {

@ -149,7 +149,7 @@ extension ReplaceTransactionCoordinator: TransactionConfirmationCoordinatorDeleg
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didFailTransaction error: Error) {
UIApplication.shared
.presentedViewController(or: presentingViewController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
func didSendTransaction(_ transaction: SentTransaction, inCoordinator coordinator: TransactionConfirmationCoordinator) {

@ -125,7 +125,7 @@ extension TransferCollectiblesCoordinator: SendSemiFungibleTokenViewControllerDe
} catch {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
}
@ -164,7 +164,7 @@ extension TransferCollectiblesCoordinator: TransactionConfirmationCoordinatorDel
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didFailTransaction error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
func didClose(in coordinator: TransactionConfirmationCoordinator) {

@ -167,7 +167,7 @@ final class SendSemiFungibleTokenViewController: UIViewController, TokenVerifiab
if let address = AlphaWallet.Address(string: targetAddressTextField.value.trimmed) {
delegate?.didEnterWalletAddress(tokenHolders: viewModel.tokenHolders, to: address, in: self)
} else {
targetAddressTextField.errorState = .error(InputError.invalidAddress.prettyError)
targetAddressTextField.errorState = .error(InputError.invalidAddress.localizedDescription)
}
}
@ -219,7 +219,7 @@ extension SendSemiFungibleTokenViewController: AddressTextFieldDelegate {
}
func displayError(error: Error, for textField: AddressTextField) {
targetAddressTextField.errorState = .error(InputError.invalidAddress.prettyError)
targetAddressTextField.errorState = .error(InputError.invalidAddress.localizedDescription)
}
func openQRCodeReader(for textField: AddressTextField) {

@ -69,7 +69,7 @@ final class SendSemiFungibleTokenViewModel {
}
}
extension RpcNodeRetryableRequestError {
extension RpcNodeRetryableRequestError: LocalizedError {
public var errorDescription: String? {
switch self {
case .possibleBinanceTestnetTimeout:
@ -89,8 +89,8 @@ extension RpcNodeRetryableRequestError {
}
}
extension SwapTokenError {
var localizedDescription: String {
extension SwapTokenError: LocalizedError {
public var errorDescription: String? {
switch self {
case .swapNotSupported:
return "Swap Not Supported"
@ -98,8 +98,8 @@ extension SwapTokenError {
}
}
extension BuyCryptoError {
var localizedDescription: String {
extension BuyCryptoError: LocalizedError {
public var errorDescription: String? {
switch self {
case .buyNotSupported:
return "Buy Crypto Not Supported"
@ -107,8 +107,8 @@ extension BuyCryptoError {
}
}
extension ActiveWalletError {
var localizedDescription: String {
extension ActiveWalletError: LocalizedError {
public var errorDescription: String? {
switch self {
case .unavailableToResolveBridgeActionProvider:
return "Unavailable To Resolve BridgeActionProvider"
@ -124,8 +124,8 @@ extension ActiveWalletError {
}
}
extension WalletApiError {
var localizedDescription: String {
extension WalletApiError: LocalizedError {
public var errorDescription: String? {
switch self {
case .connectionAddressNotFound:
return "Connection Address not Found"
@ -139,8 +139,8 @@ extension WalletApiError {
}
}
extension OpenURLError {
var localizedDescription: String {
extension OpenURLError: LocalizedError {
public var errorDescription: String? {
switch self {
case .unsupportedTokenScriptVersion:
return R.string.localizable.tokenScriptNotSupportedSchemaError()

@ -135,7 +135,7 @@ extension SendCoordinator: TransactionConfirmationCoordinatorDelegate {
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didFailTransaction error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
func didSendTransaction(_ transaction: SentTransaction, inCoordinator coordinator: TransactionConfirmationCoordinator) {

@ -10,7 +10,7 @@ protocol SignMessageCoordinatorDelegate: AnyObject {
}
extension SignMessageValidatorError: LocalizedError {
var localizedDescription: String {
public var errorDescription: String? {
switch self {
case .emptyMessage:
return R.string.localizable.signMessageValidationEmptyMessage()
@ -112,7 +112,7 @@ class SignMessageCoordinator: Coordinator {
private func showError(error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
}

@ -179,7 +179,7 @@ extension TokenScriptCoordinator: TransactionConfirmationCoordinatorDelegate {
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didFailTransaction error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
func didClose(in coordinator: TransactionConfirmationCoordinator) {
@ -250,7 +250,7 @@ extension TokenScriptCoordinator: ConfirmTokenScriptActionTransactionDelegate {
} catch {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
}
}

@ -106,7 +106,7 @@ extension TransferNFTCoordinator: SendSemiFungibleTokenViewControllerDelegate {
} catch {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
}
@ -161,7 +161,7 @@ extension TransferNFTCoordinator: TransactionConfirmationCoordinatorDelegate {
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didFailTransaction error: Error) {
UIApplication.shared
.presentedViewController(or: navigationController)
.displayError(message: error.prettyError)
.displayError(message: error.localizedDescription)
}
func didClose(in coordinator: TransactionConfirmationCoordinator) {

@ -221,7 +221,7 @@ extension SendViewController: AddressTextFieldDelegate {
}
func displayError(error: Error, for textField: AddressTextField) {
textField.errorState = .error(error.prettyError)
textField.errorState = .error(error.localizedDescription)
}
func openQRCodeReader(for textField: AddressTextField) {

@ -20,8 +20,8 @@ extension SendTransactionNotRetryableError: LocalizedError {
return message
case .executionReverted(let message):
return message
case .unknown:
return R.string.localizable.unknownError()
case .unknown(_, let message):
return message
}
}
}

@ -143,7 +143,7 @@ final class SendViewModel: TransactionTypeSupportable {
.eraseToAnyPublisher()
let recipientErrorState = isRecipientValid(inputsValidationError: inputsValidationError)
.map { $0 ? TextField.TextFieldErrorState.none : TextField.TextFieldErrorState.error(InputError.invalidAddress.prettyError) }
.map { $0 ? TextField.TextFieldErrorState.none : TextField.TextFieldErrorState.error(InputError.invalidAddress.localizedDescription) }
.eraseToAnyPublisher()
let cryptoErrorState = isCryptoValueValid(cryptoValue: input.amountToSend, send: input.send)
@ -464,7 +464,7 @@ extension TransactionTypeFromQrCode {
case serverNotMatches
case tokenNotFound
var localizedDescription: String {
var errorDescription: String? {
switch self {
case .serverNotMatches:
return "Server Not Matches"

@ -150,8 +150,8 @@ extension TransactionConfigurator.GasFeeWarning {
}
}
extension ConfigureTransactionError {
var localizedDescription: String {
extension ConfigureTransactionError: LocalizedError {
public var errorDescription: String? {
switch self {
case .gasLimitTooHigh:
return R.string.localizable.configureTransactionErrorGasLimitTooHigh(ConfigureTransaction.gasLimitMax)
@ -168,7 +168,7 @@ extension ConfigureTransactionError {
}
extension AddCustomChainError {
var localizedDescription: String {
var errorDescription: String? {
switch self {
case .cancelled:
//This is the default behavior, just keep it

@ -676,7 +676,7 @@ extension ImportWalletViewController: AddressTextFieldDelegate {
}
func displayError(error: Error, for textField: AddressTextField) {
textField.errorState = .error(error.prettyError)
textField.errorState = .error(error.localizedDescription)
}
func openQRCodeReader(for textField: AddressTextField) {

@ -28,7 +28,7 @@ extension CAIP10AccountProvidable {
}
class AnyCAIP10AccountProvidable: CAIP10AccountProvidable {
enum CAIP10AccountProvidableError: LocalizedError {
enum CAIP10AccountProvidableError: Error {
case unavailableToBuildBlockchain
case accountsNotFound
case emptyNamespaces

@ -303,7 +303,7 @@ extension WalletConnectCoordinator: WalletConnectProviderDelegate {
func provider(_ provider: WalletConnectProvider, didFail error: WalletConnectError) {
infoLog("[WalletConnect] didFail error: \(error)")
guard let description = error.localizedDescription else { return }
guard let description = error.errorDescription else { return }
displayErrorMessage(description)
}

@ -11,7 +11,7 @@ import AlphaWalletFoundation
import PromiseKit
import AlphaWalletCore
enum WalletConnectError: Error {
enum WalletConnectError: LocalizedError {
case onlyForWatchWallet(address: AlphaWallet.Address)
case walletsNotFound(addresses: [AlphaWallet.Address])
case callbackIdMissing
@ -30,7 +30,7 @@ enum WalletConnectError: Error {
} else if let error = error.embedded as? WalletConnectError {
self = error
} else {
self = .internal(.init(code: -32051, message: error.embedded.prettyError))
self = .internal(.init(code: -32051, message: error.embedded.localizedDescription))
}
}
@ -43,7 +43,7 @@ enum WalletConnectError: Error {
}
}
var localizedDescription: String? {
var errorDescription: String? {
switch self {
case .internal(let error):
return error.message

@ -8,6 +8,6 @@ class ErrorTests: XCTestCase {
func testMakeSureErrorMessageDefinedInExtensionAvailableCorrectlyAcrossFrameworks() {
//Must be stored as `Error` for test
let e: Error = KeystoreError.duplicateAccount
XCTAssertEqual(e.prettyError, "You already added this address to wallets")
XCTAssertEqual(e.localizedDescription, "You already added this address to wallets")
}
}

@ -154,7 +154,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.createHDWallet()
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { account in
@ -177,7 +177,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.createHDWallet()
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { wallet in
@ -201,7 +201,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.importWallet(json: dict.jsonString!, password: passphrase)
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { wallet in
@ -219,7 +219,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.importWallet(privateKey: privateKey)
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { wallet in
@ -254,7 +254,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.importWallet(mnemonic: words, passphrase: "")
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { wallet in
@ -280,7 +280,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.importWallet(privateKey: privateKey)
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { wallet in
@ -306,7 +306,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.watchWallet(address: address)
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { _ in
@ -325,7 +325,7 @@ class EtherKeystoreTests: XCTestCase {
keystore.watchWallet(address: address)
.sink(receiveCompletion: { result in
if case .failure(let e) = result {
XCTFail(e.prettyError)
XCTFail(e.localizedDescription)
}
expectation.fulfill()
}, receiveValue: { wallet in

@ -11,7 +11,7 @@ public struct CastError<ExpectedType>: LocalizedError {
self.expectedType = expectedType
}
public var localizedDescription: String {
public var errorDescription: String? {
return "Decode failure: Unable to decode value of \(actualValue) to expected type \(String(describing: expectedType))"
}
}

@ -2,7 +2,7 @@
import Foundation
public enum KeystoreError: LocalizedError {
public enum KeystoreError: Error {
case failedToDeleteAccount
case failedToDecryptKey
case failedToImport(Error)

@ -7,7 +7,7 @@
import Foundation
public enum SwapError: Error {
public enum SwapError: LocalizedError {
case unableToBuildSwapUnsignedTransactionFromSwapProvider
case unableToBuildSwapUnsignedTransaction(message: String)
case invalidJson
@ -16,7 +16,7 @@ public enum SwapError: Error {
case inner(Error)
case unknownError
public var localizedDescription: String {
public var errorDescription: String? {
switch self {
case .unableToBuildSwapUnsignedTransaction(let message):
return "Unable To Build Swap Unsigned Transaction: \(message)"

@ -10,7 +10,7 @@ public enum FunctionError: LocalizedError {
case formValue
case postTransaction
var localizedDescription: String {
public var errorDescription: String? {
switch self {
case .formPayload:
return "Impossible To Build Configuration! Form Payload missing"

@ -50,3 +50,25 @@ final class GetBlockTimestamp {
}
}
extension JSONRPCKit.JSONRPCError: LocalizedError {
public var errorDescription: String? {
switch self {
case .responseError(_, let message, _):
return message
case .responseNotFound:
return "Response Not Found"
case .resultObjectParseError:
return "Result Object Parse Error"
case .errorObjectParseError:
return "Error Object Parse Error"
case .unsupportedVersion(let string):
return "Unsupported Version \(string)"
case .unexpectedTypeObject:
return "Unexpected Type Object"
case .missingBothResultAndError:
return "Missing Both Result And Error"
case .nonArrayResponse:
return "Non Array Response"
}
}
}

@ -14,10 +14,10 @@ public protocol TransactionConfiguratorDelegate: AnyObject {
func updateNonce(to nonce: Int, in configurator: TransactionConfigurator)
}
public enum TransactionConfiguratorError: Error {
public enum TransactionConfiguratorError: LocalizedError {
case impossibleToBuildConfiguration
var localizedDescription: String {
public var errorDescription: String? {
return "Impossible To Build Configuration"
}
}

@ -23,7 +23,7 @@ public struct SendTransactionNotRetryableError: Error {
}
}
public enum RpcNodeRetryableRequestError: LocalizedError {
public enum RpcNodeRetryableRequestError: Error {
//TODO move those that aren't retryable to a not-retryable version
case possibleBinanceTestnetTimeout
//TODO rate limited means we should retry after delay. Or maybe all retries should have a delay

@ -7,15 +7,15 @@
import Foundation
public enum SwapTokenError: LocalizedError {
public enum SwapTokenError: Error {
case swapNotSupported
}
public enum BuyCryptoError: LocalizedError {
public enum BuyCryptoError: Error {
case buyNotSupported
}
public enum ActiveWalletError: LocalizedError {
public enum ActiveWalletError: Error {
case unavailableToResolveSwapActionProvider
case unavailableToResolveBridgeActionProvider
case bridgeNotSupported
@ -23,7 +23,7 @@ public enum ActiveWalletError: LocalizedError {
case operationForTokenNotFound
}
public enum WalletApiError: LocalizedError {
public enum WalletApiError: Error {
case connectionAddressNotFound
case requestedWalletNonActive
case requestedServerDisabled

@ -34,3 +34,9 @@ public extension JsonRpcError {
JsonRpcError(code: -32603, message: message)
}
}
extension JsonRpcError: LocalizedError {
public var errorDescription: String? {
return message
}
}

Loading…
Cancel
Save