From 09a96ec2a846c92264d36e7ed398c7d75345f298 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Sat, 22 Dec 2018 16:05:35 +0530 Subject: [PATCH] TunnelErrors: Add alert text for PacketTunnelProviderError --- WireGuard/WireGuard/Tunnel/TunnelErrors.swift | 17 +++++++++++++++++ WireGuard/WireGuard/Tunnel/TunnelsManager.swift | 17 ++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/WireGuard/WireGuard/Tunnel/TunnelErrors.swift b/WireGuard/WireGuard/Tunnel/TunnelErrors.swift index 77b0410..8e7f524 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelErrors.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelErrors.swift @@ -64,6 +64,23 @@ enum TunnelsManagerActivationError: WireGuardAppError { } } +extension PacketTunnelProviderError: WireGuardAppError { + var alertText: AlertText { + switch self { + case .savedProtocolConfigurationIsInvalid: + return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationSavedConfigFailureMessage")) + case .dnsResolutionFailure: + return (tr("alertTunnelDNSFailureTitle"), tr("alertTunnelDNSFailureMessage")) + case .couldNotStartBackend: + return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationBackendFailureMessage")) + case .couldNotDetermineFileDescriptor: + return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFileDescriptorFailureMessage")) + case .couldNotSetNetworkSettings: + return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationSetNetworkSettingsMessage")) + } + } +} + extension Error { var localizedUIString: String { if let systemError = self as? NEVPNError { diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index da1b217..6b24a58 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -323,20 +323,11 @@ private func lastErrorTextFromNetworkExtension(for tunnel: TunnelContainer) -> ( guard let lastErrorStrings = String(data: lastErrorData, encoding: .utf8)?.splitToArray(separator: "\n") else { return nil } guard lastErrorStrings.count == 2 && tunnel.activationAttemptId == lastErrorStrings[0] else { return nil } - switch PacketTunnelProviderError(rawValue: lastErrorStrings[1]) { - case .some(.savedProtocolConfigurationIsInvalid): - return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationSavedConfigFailureMessage")) - case .some(.dnsResolutionFailure): - return (tr("alertTunnelDNSFailureTitle"), tr("alertTunnelDNSFailureMessage")) - case .some(.couldNotStartBackend): - return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationBackendFailureMessage")) - case .some(.couldNotDetermineFileDescriptor): - return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFileDescriptorFailureMessage")) - case .some(.couldNotSetNetworkSettings): - return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationSetNetworkSettingsMessage")) - default: - return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFailureMessage")) + if let extensionError = PacketTunnelProviderError(rawValue: lastErrorStrings[1]) { + return extensionError.alertText } + + return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFailureMessage")) } class TunnelContainer: NSObject {