From ae2bd3d876f3033754cbe8d5817306c3fa8f7e8a Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 19 Oct 2018 01:01:11 +0200 Subject: [PATCH] Replace some profile exceptions with preconditions Misconfigured profiles must fall back to a consistent state, this is a programming error. - provider.pool: fall back to default pool (should always be there) - provider.preset: why would one remove a preset? - host.endpointProtocols: .ovpn with no remotes shouldn't get this far --- Passepartout/Sources/ApplicationError.swift | 6 ------ .../Sources/Model/Profiles/HostConnectionProfile.swift | 4 +--- .../Sources/Model/Profiles/ProviderConnectionProfile.swift | 6 +++--- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Passepartout/Sources/ApplicationError.swift b/Passepartout/Sources/ApplicationError.swift index d99bf98a..fe26d9e6 100644 --- a/Passepartout/Sources/ApplicationError.swift +++ b/Passepartout/Sources/ApplicationError.swift @@ -30,12 +30,6 @@ enum ApplicationError: Error { case missingCredentials - case providerPool - - case providerPreset - - case hostEndpoints - case missingCA case emptyRemotes diff --git a/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift b/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift index 130cb08a..0e683e0c 100644 --- a/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift +++ b/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift @@ -52,9 +52,7 @@ class HostConnectionProfile: ConnectionProfile, Codable, Equatable { } func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { - guard !parameters.endpointProtocols.isEmpty else { - throw ApplicationError.hostEndpoints - } + precondition(!parameters.endpointProtocols.isEmpty) // XXX: copy paste, error prone var builder = parameters.builder() diff --git a/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift b/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift index 22c28c9b..7e86c93c 100644 --- a/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift +++ b/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift @@ -40,7 +40,7 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable { } var pool: Pool? { - return infrastructure.pool(for: poolId) + return infrastructure.pool(for: poolId) ?? infrastructure.pool(for: infrastructure.defaults.pool) } var presetId: String { @@ -107,10 +107,10 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable { func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { guard let pool = pool else { - throw ApplicationError.providerPool + preconditionFailure("Nil pool?") } guard let preset = preset else { - throw ApplicationError.providerPreset + preconditionFailure("Nil preset?") } // assert(!pool.numericAddresses.isEmpty)