Throw error on reinstate()/connect() (#328)

Errors here were just being ignored, thus preventing error alert from
appearing.
This commit is contained in:
Davide De Rosa 2023-07-06 18:45:43 +01:00 committed by GitHub
parent a7ea010d4e
commit 33af87206a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 12 deletions

View File

@ -87,7 +87,7 @@ public final class VPNManager: ObservableObject {
clearLastError() clearLastError()
do { do {
let parameters = try vpnConfigurationParameters(withProfile: profile) let parameters = try vpnConfigurationParameters(withProfile: profile)
await strategy.reinstate(parameters) try await strategy.reinstate(parameters)
} catch { } catch {
pp_log.error("Unable to build configuration: \(error)") pp_log.error("Unable to build configuration: \(error)")
throw error throw error
@ -99,7 +99,7 @@ public final class VPNManager: ObservableObject {
clearLastError() clearLastError()
do { do {
let parameters = try vpnConfigurationParameters(withProfile: profile) let parameters = try vpnConfigurationParameters(withProfile: profile)
await strategy.connect(parameters) try await strategy.connect(parameters)
} catch { } catch {
pp_log.error("Unable to build configuration: \(error)") pp_log.error("Unable to build configuration: \(error)")
throw error throw error

View File

@ -31,9 +31,9 @@ import PassepartoutProviders
public protocol VPNManagerStrategy { public protocol VPNManagerStrategy {
func observe(into state: MutableObservableVPNState) func observe(into state: MutableObservableVPNState)
func reinstate(_ parameters: VPNConfigurationParameters) async func reinstate(_ parameters: VPNConfigurationParameters) async throws
func connect(_ parameters: VPNConfigurationParameters) async func connect(_ parameters: VPNConfigurationParameters) async throws
func reconnect() async func reconnect() async

View File

@ -132,10 +132,8 @@ extension TunnelKitVPNManagerStrategy {
}.store(in: &cancellables) }.store(in: &cancellables)
} }
public func reinstate(_ parameters: VPNConfigurationParameters) async { public func reinstate(_ parameters: VPNConfigurationParameters) async throws {
guard let configuration = try? vpnConfiguration(withParameters: parameters) else { let configuration = try vpnConfiguration(withParameters: parameters)
return
}
guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else { guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else {
fatalError("Configuration must implement VPNProtocolProviding") fatalError("Configuration must implement VPNProtocolProviding")
} }
@ -155,10 +153,8 @@ extension TunnelKitVPNManagerStrategy {
} }
} }
public func connect(_ parameters: VPNConfigurationParameters) async { public func connect(_ parameters: VPNConfigurationParameters) async throws {
guard let configuration = try? vpnConfiguration(withParameters: parameters) else { let configuration = try vpnConfiguration(withParameters: parameters)
return
}
guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else { guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else {
fatalError("Configuration must implement VPNProtocolProviding") fatalError("Configuration must implement VPNProtocolProviding")
} }