UI: Avoid force unwrap when checking for errors
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
This commit is contained in:
parent
b67acaccff
commit
6d57c8b6f9
|
@ -138,10 +138,10 @@ class TunnelsManager {
|
||||||
let activeTunnel = tunnels.first { $0.status == .active || $0.status == .activating }
|
let activeTunnel = tunnels.first { $0.status == .active || $0.status == .activating }
|
||||||
|
|
||||||
tunnelProviderManager.saveToPreferences { [weak self] error in
|
tunnelProviderManager.saveToPreferences { [weak self] error in
|
||||||
guard error == nil else {
|
if let error = error {
|
||||||
wg_log(.error, message: "Add: Saving configuration failed: \(error!)")
|
wg_log(.error, message: "Add: Saving configuration failed: \(error)")
|
||||||
(tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.destroyConfigurationReference()
|
(tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.destroyConfigurationReference()
|
||||||
completionHandler(.failure(TunnelsManagerError.systemErrorOnAddTunnel(systemError: error!)))
|
completionHandler(.failure(TunnelsManagerError.systemErrorOnAddTunnel(systemError: error)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,10 +235,10 @@ class TunnelsManager {
|
||||||
onDemandOption.apply(on: tunnelProviderManager)
|
onDemandOption.apply(on: tunnelProviderManager)
|
||||||
|
|
||||||
tunnelProviderManager.saveToPreferences { [weak self] error in
|
tunnelProviderManager.saveToPreferences { [weak self] error in
|
||||||
guard error == nil else {
|
if let error = error {
|
||||||
//TODO: the passwordReference for the old one has already been removed at this point and we can't easily roll back!
|
//TODO: the passwordReference for the old one has already been removed at this point and we can't easily roll back!
|
||||||
wg_log(.error, message: "Modify: Saving configuration failed: \(error!)")
|
wg_log(.error, message: "Modify: Saving configuration failed: \(error)")
|
||||||
completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel(systemError: error!))
|
completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel(systemError: error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
@ -266,13 +266,13 @@ class TunnelsManager {
|
||||||
// Without this, the tunnel stopes getting updates on the tunnel status from iOS.
|
// Without this, the tunnel stopes getting updates on the tunnel status from iOS.
|
||||||
tunnelProviderManager.loadFromPreferences { error in
|
tunnelProviderManager.loadFromPreferences { error in
|
||||||
tunnel.isActivateOnDemandEnabled = tunnelProviderManager.isOnDemandEnabled
|
tunnel.isActivateOnDemandEnabled = tunnelProviderManager.isOnDemandEnabled
|
||||||
guard error == nil else {
|
if let error = error {
|
||||||
wg_log(.error, message: "Modify: Re-loading after saving configuration failed: \(error!)")
|
wg_log(.error, message: "Modify: Re-loading after saving configuration failed: \(error)")
|
||||||
completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel(systemError: error!))
|
completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel(systemError: error))
|
||||||
return
|
} else {
|
||||||
}
|
|
||||||
completionHandler(nil)
|
completionHandler(nil)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
completionHandler(nil)
|
completionHandler(nil)
|
||||||
}
|
}
|
||||||
|
@ -291,9 +291,9 @@ class TunnelsManager {
|
||||||
#error("Unimplemented")
|
#error("Unimplemented")
|
||||||
#endif
|
#endif
|
||||||
tunnelProviderManager.removeFromPreferences { [weak self] error in
|
tunnelProviderManager.removeFromPreferences { [weak self] error in
|
||||||
guard error == nil else {
|
if let error = error {
|
||||||
wg_log(.error, message: "Remove: Saving configuration failed: \(error!)")
|
wg_log(.error, message: "Remove: Saving configuration failed: \(error)")
|
||||||
completionHandler(TunnelsManagerError.systemErrorOnRemoveTunnel(systemError: error!))
|
completionHandler(TunnelsManagerError.systemErrorOnRemoveTunnel(systemError: error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let self = self, let index = self.tunnels.firstIndex(of: tunnel) {
|
if let self = self, let index = self.tunnels.firstIndex(of: tunnel) {
|
||||||
|
|
Loading…
Reference in New Issue