diff --git a/Example/example-app/Sources/AppFeature/PasswordStorage+Keychain.swift b/Example/example-app/Sources/AppFeature/PasswordStorage+Keychain.swift index 7af6bc4faa48b2b35a7a7a5eb8583f31998c5e14..5eb1a61d6b07cb9197b443f98226b8257b6cc5f9 100644 --- a/Example/example-app/Sources/AppFeature/PasswordStorage+Keychain.swift +++ b/Example/example-app/Sources/AppFeature/PasswordStorage+Keychain.swift @@ -8,7 +8,7 @@ extension PasswordStorage { ) return PasswordStorage( save: { password in keychain[data: "password"] = password}, - load: { try keychain[data: "password"] ?? { throw PasswordStorageMissingPasswordError() }() } + load: { try keychain[data: "password"] ?? { throw MissingPasswordError() }() } ) }() } diff --git a/Sources/ElixxirDAppsSDK/ClientCreator.swift b/Sources/ElixxirDAppsSDK/ClientCreator.swift index e048227edb7b0db96fc42362725acb2bbf519d44..9e698645cb98323c6e1e39394ebe325fa20ae3e9 100644 --- a/Sources/ElixxirDAppsSDK/ClientCreator.swift +++ b/Sources/ElixxirDAppsSDK/ClientCreator.swift @@ -17,7 +17,7 @@ extension ClientCreator { throw error } if !created { - throw BindingsNewClientUnknownError() + fatalError("BindingsNewClient returned `false` without providing error") } } } diff --git a/Sources/ElixxirDAppsSDK/ClientLoader.swift b/Sources/ElixxirDAppsSDK/ClientLoader.swift index 632f01070f054694ab261c5b045e6956060b29a2..7c1ca48a5972eb644509ac569b167eeb31a64172 100644 --- a/Sources/ElixxirDAppsSDK/ClientLoader.swift +++ b/Sources/ElixxirDAppsSDK/ClientLoader.swift @@ -12,9 +12,11 @@ extension ClientLoader { public static let live = ClientLoader { directoryURL, password in var error: NSError? let bindingsClient = BindingsLogin(directoryURL.path, password, &error) - if let error = error { throw error } + if let error = error { + throw error + } guard let bindingsClient = bindingsClient else { - throw BindingsLoginUnknownError() + fatalError("BindingsLogin returned `nil` without providing error") } return Client.live(bindingsClient: bindingsClient) } diff --git a/Sources/ElixxirDAppsSDK/ClientStorage.swift b/Sources/ElixxirDAppsSDK/ClientStorage.swift index 8471fa783efd5d7cd6ce80007bd9708d17ce3229..7c18828b69e30f48fd14c69ec16913d2785bc784 100644 --- a/Sources/ElixxirDAppsSDK/ClientStorage.swift +++ b/Sources/ElixxirDAppsSDK/ClientStorage.swift @@ -30,7 +30,7 @@ extension ClientStorage { }, createClient: { let ndf = try downloadNDF(environment) - let password = try generatePassword() + let password = generatePassword() try passwordStorage.save(password) try? fileManager.removeItem(at: directoryURL) try? fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true) diff --git a/Sources/ElixxirDAppsSDK/Errors.swift b/Sources/ElixxirDAppsSDK/Errors.swift deleted file mode 100644 index d28f5bafc0e6843d9a43a6f10171c5fa35596437..0000000000000000000000000000000000000000 --- a/Sources/ElixxirDAppsSDK/Errors.swift +++ /dev/null @@ -1,19 +0,0 @@ -public struct BindingsDownloadAndVerifySignedNdfWithUrlUnknownError: Error, Equatable { - public init() {} -} - -public struct BindingsGenerateSecretUnknownError: Error, Equatable { - public init() {} -} - -public struct PasswordStorageMissingPasswordError: Error, Equatable { - public init() {} -} - -public struct BindingsNewClientUnknownError: Error, Equatable { - public init() {} -} - -public struct BindingsLoginUnknownError: Error, Equatable { - public init() {} -} diff --git a/Sources/ElixxirDAppsSDK/NDFDownloader.swift b/Sources/ElixxirDAppsSDK/NDFDownloader.swift index c0552b99985d3a9b4c3a52fc554b2fad2a92a61c..fed3385073a483752931e8eade5479229512d531 100644 --- a/Sources/ElixxirDAppsSDK/NDFDownloader.swift +++ b/Sources/ElixxirDAppsSDK/NDFDownloader.swift @@ -20,7 +20,7 @@ extension NDFDownloader { throw error } guard let data = data else { - throw BindingsDownloadAndVerifySignedNdfWithUrlUnknownError() + fatalError("BindingsDownloadAndVerifySignedNdfWithUrl returned `nil` without providing error") } return data } diff --git a/Sources/ElixxirDAppsSDK/PasswordGenerator.swift b/Sources/ElixxirDAppsSDK/PasswordGenerator.swift index 251ea87399bbcd310c56dd78af6908d802f3aaf1..949dfdb29ad61e03985d93ab922de730c4e440fd 100644 --- a/Sources/ElixxirDAppsSDK/PasswordGenerator.swift +++ b/Sources/ElixxirDAppsSDK/PasswordGenerator.swift @@ -1,17 +1,17 @@ import Bindings public struct PasswordGenerator { - public var run: () throws -> Data + public var run: () -> Data - public func callAsFunction() throws -> Data { - try run() + public func callAsFunction() -> Data { + run() } } extension PasswordGenerator { public static let live = PasswordGenerator { guard let secret = BindingsGenerateSecret(32) else { - throw BindingsGenerateSecretUnknownError() + fatalError("BindingsGenerateSecret returned `nil`") } return secret } @@ -20,8 +20,7 @@ extension PasswordGenerator { #if DEBUG extension PasswordGenerator { public static let failing = PasswordGenerator { - struct NotImplemented: Error {} - throw NotImplemented() + Data() } } #endif diff --git a/Sources/ElixxirDAppsSDK/PasswordStorage.swift b/Sources/ElixxirDAppsSDK/PasswordStorage.swift index 82ae04dcd844cd97c365bec9fe2f1d9170043a59..89df9af8f14b84fc947e9e7ef4059488a295f504 100644 --- a/Sources/ElixxirDAppsSDK/PasswordStorage.swift +++ b/Sources/ElixxirDAppsSDK/PasswordStorage.swift @@ -1,6 +1,10 @@ import Foundation public struct PasswordStorage { + public struct MissingPasswordError: Error, Equatable { + public init() {} + } + public init( save: @escaping (Data) throws -> Void, load: @escaping () throws -> Data