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
This commit is contained in:
parent
5e0590184b
commit
ae2bd3d876
|
@ -30,12 +30,6 @@ enum ApplicationError: Error {
|
||||||
|
|
||||||
case missingCredentials
|
case missingCredentials
|
||||||
|
|
||||||
case providerPool
|
|
||||||
|
|
||||||
case providerPreset
|
|
||||||
|
|
||||||
case hostEndpoints
|
|
||||||
|
|
||||||
case missingCA
|
case missingCA
|
||||||
|
|
||||||
case emptyRemotes
|
case emptyRemotes
|
||||||
|
|
|
@ -52,9 +52,7 @@ class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
|
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
|
||||||
guard !parameters.endpointProtocols.isEmpty else {
|
precondition(!parameters.endpointProtocols.isEmpty)
|
||||||
throw ApplicationError.hostEndpoints
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: copy paste, error prone
|
// XXX: copy paste, error prone
|
||||||
var builder = parameters.builder()
|
var builder = parameters.builder()
|
||||||
|
|
|
@ -40,7 +40,7 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
var pool: Pool? {
|
var pool: Pool? {
|
||||||
return infrastructure.pool(for: poolId)
|
return infrastructure.pool(for: poolId) ?? infrastructure.pool(for: infrastructure.defaults.pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
var presetId: String {
|
var presetId: String {
|
||||||
|
@ -107,10 +107,10 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
||||||
|
|
||||||
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
|
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
|
||||||
guard let pool = pool else {
|
guard let pool = pool else {
|
||||||
throw ApplicationError.providerPool
|
preconditionFailure("Nil pool?")
|
||||||
}
|
}
|
||||||
guard let preset = preset else {
|
guard let preset = preset else {
|
||||||
throw ApplicationError.providerPreset
|
preconditionFailure("Nil preset?")
|
||||||
}
|
}
|
||||||
|
|
||||||
// assert(!pool.numericAddresses.isEmpty)
|
// assert(!pool.numericAddresses.isEmpty)
|
||||||
|
|
Loading…
Reference in New Issue