mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
refactor(apple): tidy up error handling around Session.start (#5968)
Whilst investigating #5965, I noticed that the code around `Adapter.start` on the Swift side can be tidied up a bit to prevent duplicate logs.
This commit is contained in:
@@ -106,14 +106,10 @@ class Adapter {
|
||||
}
|
||||
|
||||
/// Start the tunnel.
|
||||
/// - Parameters:
|
||||
/// - completionHandler: completion handler.
|
||||
public func start(completionHandler: @escaping (AdapterError?) -> Void) throws {
|
||||
public func start() throws {
|
||||
Log.tunnel.log("Adapter.start")
|
||||
guard case .tunnelStopped = self.state else {
|
||||
Log.tunnel.error("\(#function): Invalid Adapter state")
|
||||
completionHandler(.invalidState)
|
||||
return
|
||||
throw AdapterError.invalidState
|
||||
}
|
||||
|
||||
callbackHandler.delegate = self
|
||||
@@ -136,20 +132,15 @@ class Adapter {
|
||||
logFilter,
|
||||
callbackHandler
|
||||
)
|
||||
// Update our internal state
|
||||
self.state = .tunnelStarted(session: session)
|
||||
|
||||
// Start listening for network change events. The first few will be our
|
||||
// tunnel interface coming up, but that's ok -- it will trigger a `set_dns`
|
||||
// connlib.
|
||||
beginPathMonitoring()
|
||||
|
||||
// Tell the system the tunnel is up, moving the tunnelManager status to
|
||||
// `connected`.
|
||||
completionHandler(nil)
|
||||
// Update state in case everything succeeded
|
||||
self.state = .tunnelStarted(session: session)
|
||||
} catch let error {
|
||||
Log.tunnel.error("\(#function): Adapter.start: Error: \(error)")
|
||||
state = .tunnelStopped
|
||||
throw AdapterError.connlibConnectError(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,11 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
apiURL: apiURL, token: token, logFilter: logFilter, packetTunnelProvider: self)
|
||||
self.adapter = adapter
|
||||
|
||||
try adapter.start(completionHandler: completionHandler)
|
||||
try adapter.start()
|
||||
|
||||
// Tell the system the tunnel is up, moving the tunnelManager status to
|
||||
// `connected`.
|
||||
completionHandler(nil)
|
||||
} catch {
|
||||
Log.tunnel.error("\(#function): Error! \(error)")
|
||||
completionHandler(error)
|
||||
|
||||
Reference in New Issue
Block a user