2024-09-23 13:02:26 +00:00
|
|
|
//
|
|
|
|
// AppError+L10n.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 8/27/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CommonLibrary
|
2024-11-02 09:11:59 +00:00
|
|
|
import CommonUtils
|
2024-09-23 13:02:26 +00:00
|
|
|
import Foundation
|
|
|
|
import PassepartoutKit
|
|
|
|
|
|
|
|
extension AppError: LocalizedError {
|
2024-10-29 13:30:41 +00:00
|
|
|
public var errorDescription: String? {
|
2024-09-23 13:02:26 +00:00
|
|
|
let V = Strings.Errors.App.self
|
|
|
|
switch self {
|
2024-11-07 22:02:10 +00:00
|
|
|
case .emptyProducts:
|
|
|
|
return V.emptyProducts
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
case .emptyProfileName:
|
|
|
|
return V.emptyProfileName
|
|
|
|
|
|
|
|
case .malformedModule(let module, let error):
|
2024-11-02 14:23:36 +00:00
|
|
|
return V.malformedModule(module.moduleType.localizedDescription, error.localizedDescription)
|
2024-09-23 13:02:26 +00:00
|
|
|
|
|
|
|
case .permissionDenied:
|
|
|
|
return V.default
|
|
|
|
|
|
|
|
case .generic(let error):
|
|
|
|
return error.localizedDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - App side
|
|
|
|
|
|
|
|
extension PassepartoutError: LocalizedError {
|
|
|
|
public var errorDescription: String? {
|
|
|
|
switch code {
|
2024-11-05 09:03:54 +00:00
|
|
|
case .App.expiredProfile:
|
|
|
|
return Strings.Errors.App.expiredProfile
|
|
|
|
|
2024-10-16 07:50:26 +00:00
|
|
|
case .connectionModuleRequired:
|
|
|
|
return Strings.Errors.App.Passepartout.connectionModuleRequired
|
|
|
|
|
|
|
|
case .corruptProviderModule:
|
|
|
|
return Strings.Errors.App.Passepartout.corruptProviderModule(reason?.localizedDescription ?? "")
|
|
|
|
|
|
|
|
case .incompatibleModules:
|
|
|
|
return Strings.Errors.App.Passepartout.incompatibleModules
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
case .invalidFields:
|
2024-10-28 19:07:19 +00:00
|
|
|
let fields = (userInfo as? [String: String?])
|
2024-09-23 13:02:26 +00:00
|
|
|
.map {
|
2024-10-28 19:07:19 +00:00
|
|
|
$0.map {
|
|
|
|
"\($0)=\($1?.description ?? "")"
|
|
|
|
}
|
|
|
|
.joined(separator: ",")
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
|
2024-10-28 19:07:19 +00:00
|
|
|
return [Strings.Errors.App.Passepartout.invalidFields, fields]
|
|
|
|
.compactMap { $0 }
|
|
|
|
.joined(separator: " ")
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-01 19:01:18 +00:00
|
|
|
case .noActiveModules:
|
|
|
|
return Strings.Errors.App.Passepartout.noActiveModules
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
case .parsing:
|
2024-10-28 19:07:19 +00:00
|
|
|
let message = userInfo as? String ?? reason?.localizedDescription
|
|
|
|
|
|
|
|
return [Strings.Errors.App.Passepartout.parsing, message]
|
|
|
|
.compactMap { $0 }
|
|
|
|
.joined(separator: " ")
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-10-28 19:30:22 +00:00
|
|
|
case .providerRequired:
|
|
|
|
return Strings.Errors.App.Passepartout.providerRequired
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
case .unhandled:
|
|
|
|
return reason?.localizedDescription
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Strings.Errors.App.Passepartout.default(code.rawValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Tunnel side
|
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
extension PassepartoutError.Code: StyledLocalizableEntity {
|
|
|
|
public enum Style {
|
|
|
|
case tunnel
|
|
|
|
}
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
public func localizedDescription(style: Style) -> String {
|
|
|
|
switch style {
|
|
|
|
case .tunnel:
|
|
|
|
let V = Strings.Errors.Tunnel.self
|
|
|
|
switch self {
|
2024-11-05 09:03:54 +00:00
|
|
|
case .App.expiredProfile:
|
|
|
|
return V.expired
|
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .authentication:
|
|
|
|
return V.auth
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .crypto:
|
|
|
|
return V.encryption
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .dnsFailure:
|
|
|
|
return V.dns
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .timeout:
|
|
|
|
return V.timeout
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .OpenVPN.compressionMismatch:
|
|
|
|
return V.compression
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .OpenVPN.noRouting:
|
|
|
|
return V.routing
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .OpenVPN.serverShutdown:
|
|
|
|
return V.shutdown
|
2024-09-23 13:02:26 +00:00
|
|
|
|
2024-11-04 22:34:22 +00:00
|
|
|
case .OpenVPN.tlsFailure:
|
|
|
|
return V.tls
|
|
|
|
|
|
|
|
default:
|
|
|
|
return V.generic
|
|
|
|
}
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|