2018-12-17 13:26:26 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2023-02-14 15:10:32 +00:00
|
|
|
// Copyright © 2018-2023 WireGuard LLC. All Rights Reserved.
|
2018-12-17 13:26:26 +00:00
|
|
|
|
|
|
|
import NetworkExtension
|
|
|
|
|
|
|
|
enum TunnelsManagerError: WireGuardAppError {
|
|
|
|
case tunnelNameEmpty
|
|
|
|
case tunnelAlreadyExistsWithThatName
|
|
|
|
case systemErrorOnListingTunnels(systemError: Error)
|
|
|
|
case systemErrorOnAddTunnel(systemError: Error)
|
|
|
|
case systemErrorOnModifyTunnel(systemError: Error)
|
|
|
|
case systemErrorOnRemoveTunnel(systemError: Error)
|
|
|
|
|
|
|
|
var alertText: AlertText {
|
|
|
|
switch self {
|
|
|
|
case .tunnelNameEmpty:
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertTunnelNameEmptyTitle"), tr("alertTunnelNameEmptyMessage"))
|
2018-12-17 13:26:26 +00:00
|
|
|
case .tunnelAlreadyExistsWithThatName:
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertTunnelAlreadyExistsWithThatNameTitle"), tr("alertTunnelAlreadyExistsWithThatNameMessage"))
|
2018-12-17 13:26:26 +00:00
|
|
|
case .systemErrorOnListingTunnels(let systemError):
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertSystemErrorOnListingTunnelsTitle"), systemError.localizedUIString)
|
2018-12-17 13:26:26 +00:00
|
|
|
case .systemErrorOnAddTunnel(let systemError):
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertSystemErrorOnAddTunnelTitle"), systemError.localizedUIString)
|
2018-12-17 13:26:26 +00:00
|
|
|
case .systemErrorOnModifyTunnel(let systemError):
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertSystemErrorOnModifyTunnelTitle"), systemError.localizedUIString)
|
2018-12-17 13:26:26 +00:00
|
|
|
case .systemErrorOnRemoveTunnel(let systemError):
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertSystemErrorOnRemoveTunnelTitle"), systemError.localizedUIString)
|
2018-12-17 13:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum TunnelsManagerActivationAttemptError: WireGuardAppError {
|
|
|
|
case tunnelIsNotInactive
|
|
|
|
case failedWhileStarting(systemError: Error) // startTunnel() throwed
|
|
|
|
case failedWhileSaving(systemError: Error) // save config after re-enabling throwed
|
|
|
|
case failedWhileLoading(systemError: Error) // reloading config throwed
|
|
|
|
case failedBecauseOfTooManyErrors(lastSystemError: Error) // recursion limit reached
|
|
|
|
|
|
|
|
var alertText: AlertText {
|
|
|
|
switch self {
|
|
|
|
case .tunnelIsNotInactive:
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertTunnelActivationErrorTunnelIsNotInactiveTitle"), tr("alertTunnelActivationErrorTunnelIsNotInactiveMessage"))
|
2018-12-17 13:26:26 +00:00
|
|
|
case .failedWhileStarting(let systemError),
|
|
|
|
.failedWhileSaving(let systemError),
|
|
|
|
.failedWhileLoading(let systemError),
|
|
|
|
.failedBecauseOfTooManyErrors(let systemError):
|
2018-12-18 11:00:16 +00:00
|
|
|
return (tr("alertTunnelActivationSystemErrorTitle"),
|
|
|
|
tr(format: "alertTunnelActivationSystemErrorMessage (%@)", systemError.localizedUIString))
|
2018-12-17 13:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum TunnelsManagerActivationError: WireGuardAppError {
|
2018-12-21 17:50:32 +00:00
|
|
|
case activationFailed(wasOnDemandEnabled: Bool)
|
|
|
|
case activationFailedWithExtensionError(title: String, message: String, wasOnDemandEnabled: Bool)
|
2018-12-21 22:34:56 +00:00
|
|
|
|
2018-12-17 13:26:26 +00:00
|
|
|
var alertText: AlertText {
|
|
|
|
switch self {
|
2021-07-28 06:21:23 +00:00
|
|
|
case .activationFailed:
|
|
|
|
return (tr("alertTunnelActivationFailureTitle"), tr("alertTunnelActivationFailureMessage"))
|
|
|
|
case .activationFailedWithExtensionError(let title, let message, _):
|
|
|
|
return (title, message)
|
2018-12-17 13:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:35:35 +00:00
|
|
|
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"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 13:26:26 +00:00
|
|
|
extension Error {
|
2018-12-18 11:00:16 +00:00
|
|
|
var localizedUIString: String {
|
2018-12-17 13:26:26 +00:00
|
|
|
if let systemError = self as? NEVPNError {
|
|
|
|
switch systemError {
|
|
|
|
case NEVPNError.configurationInvalid:
|
2018-12-18 11:00:16 +00:00
|
|
|
return tr("alertSystemErrorMessageTunnelConfigurationInvalid")
|
2018-12-17 13:26:26 +00:00
|
|
|
case NEVPNError.configurationDisabled:
|
2018-12-18 11:00:16 +00:00
|
|
|
return tr("alertSystemErrorMessageTunnelConfigurationDisabled")
|
2018-12-17 13:26:26 +00:00
|
|
|
case NEVPNError.connectionFailed:
|
2018-12-18 11:00:16 +00:00
|
|
|
return tr("alertSystemErrorMessageTunnelConnectionFailed")
|
2018-12-17 13:26:26 +00:00
|
|
|
case NEVPNError.configurationStale:
|
2018-12-18 11:00:16 +00:00
|
|
|
return tr("alertSystemErrorMessageTunnelConfigurationStale")
|
2018-12-17 13:26:26 +00:00
|
|
|
case NEVPNError.configurationReadWriteFailed:
|
2018-12-18 11:00:16 +00:00
|
|
|
return tr("alertSystemErrorMessageTunnelConfigurationReadWriteFailed")
|
2018-12-17 13:26:26 +00:00
|
|
|
case NEVPNError.configurationUnknown:
|
2018-12-18 11:00:16 +00:00
|
|
|
return tr("alertSystemErrorMessageTunnelConfigurationUnknown")
|
2018-12-17 13:26:26 +00:00
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return localizedDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|