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 providerPool
|
||||
|
||||
case providerPreset
|
||||
|
||||
case hostEndpoints
|
||||
|
||||
case missingCA
|
||||
|
||||
case emptyRemotes
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue