Skip to content
Snippets Groups Projects
Commit bf349a01 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Replace unknown Bindings errors with fatalError

parent 5a5091ad
No related branches found
No related tags found
1 merge request!2Bindings API wrapper
...@@ -8,7 +8,7 @@ extension PasswordStorage { ...@@ -8,7 +8,7 @@ extension PasswordStorage {
) )
return PasswordStorage( return PasswordStorage(
save: { password in keychain[data: "password"] = password}, save: { password in keychain[data: "password"] = password},
load: { try keychain[data: "password"] ?? { throw PasswordStorageMissingPasswordError() }() } load: { try keychain[data: "password"] ?? { throw MissingPasswordError() }() }
) )
}() }()
} }
...@@ -17,7 +17,7 @@ extension ClientCreator { ...@@ -17,7 +17,7 @@ extension ClientCreator {
throw error throw error
} }
if !created { if !created {
throw BindingsNewClientUnknownError() fatalError("BindingsNewClient returned `false` without providing error")
} }
} }
} }
......
...@@ -12,9 +12,11 @@ extension ClientLoader { ...@@ -12,9 +12,11 @@ extension ClientLoader {
public static let live = ClientLoader { directoryURL, password in public static let live = ClientLoader { directoryURL, password in
var error: NSError? var error: NSError?
let bindingsClient = BindingsLogin(directoryURL.path, password, &error) let bindingsClient = BindingsLogin(directoryURL.path, password, &error)
if let error = error { throw error } if let error = error {
throw error
}
guard let bindingsClient = bindingsClient else { guard let bindingsClient = bindingsClient else {
throw BindingsLoginUnknownError() fatalError("BindingsLogin returned `nil` without providing error")
} }
return Client.live(bindingsClient: bindingsClient) return Client.live(bindingsClient: bindingsClient)
} }
......
...@@ -30,7 +30,7 @@ extension ClientStorage { ...@@ -30,7 +30,7 @@ extension ClientStorage {
}, },
createClient: { createClient: {
let ndf = try downloadNDF(environment) let ndf = try downloadNDF(environment)
let password = try generatePassword() let password = generatePassword()
try passwordStorage.save(password) try passwordStorage.save(password)
try? fileManager.removeItem(at: directoryURL) try? fileManager.removeItem(at: directoryURL)
try? fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true) try? fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true)
......
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() {}
}
...@@ -20,7 +20,7 @@ extension NDFDownloader { ...@@ -20,7 +20,7 @@ extension NDFDownloader {
throw error throw error
} }
guard let data = data else { guard let data = data else {
throw BindingsDownloadAndVerifySignedNdfWithUrlUnknownError() fatalError("BindingsDownloadAndVerifySignedNdfWithUrl returned `nil` without providing error")
} }
return data return data
} }
......
import Bindings import Bindings
public struct PasswordGenerator { public struct PasswordGenerator {
public var run: () throws -> Data public var run: () -> Data
public func callAsFunction() throws -> Data { public func callAsFunction() -> Data {
try run() run()
} }
} }
extension PasswordGenerator { extension PasswordGenerator {
public static let live = PasswordGenerator { public static let live = PasswordGenerator {
guard let secret = BindingsGenerateSecret(32) else { guard let secret = BindingsGenerateSecret(32) else {
throw BindingsGenerateSecretUnknownError() fatalError("BindingsGenerateSecret returned `nil`")
} }
return secret return secret
} }
...@@ -20,8 +20,7 @@ extension PasswordGenerator { ...@@ -20,8 +20,7 @@ extension PasswordGenerator {
#if DEBUG #if DEBUG
extension PasswordGenerator { extension PasswordGenerator {
public static let failing = PasswordGenerator { public static let failing = PasswordGenerator {
struct NotImplemented: Error {} Data()
throw NotImplemented()
} }
} }
#endif #endif
import Foundation import Foundation
public struct PasswordStorage { public struct PasswordStorage {
public struct MissingPasswordError: Error, Equatable {
public init() {}
}
public init( public init(
save: @escaping (Data) throws -> Void, save: @escaping (Data) throws -> Void,
load: @escaping () throws -> Data load: @escaping () throws -> Data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment