summaryrefslogtreecommitdiffhomepage
path: root/ios/PacketTunnel/WireGuardAdapterError+Localization.swift
blob: 6a88af373d0b9dc4b2d903d05490803525575b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
//  WireGuardAdapterError+Localization.swift
//  PacketTunnel
//
//  Created by pronebird on 14/07/2022.
//  Copyright © 2022 Mullvad VPN AB. All rights reserved.
//

import Foundation
import WireGuardKit

extension WireGuardAdapterError: LocalizedError {
    public var errorDescription: String? {
        switch self {
        case .cannotLocateTunnelFileDescriptor:
            return "Failure to locate tunnel file descriptor."

        case .invalidState:
            return "Failure to perform an operation in such state."

        case let .dnsResolution(resolutionErrors):
            let detailedErrorDescription = resolutionErrors
                .enumerated()
                .map { index, dnsResolutionError in
                    let errorDescription = dnsResolutionError.errorDescription ?? "???"

                    return "\(index): \(dnsResolutionError.address) \(errorDescription)"
                }
                .joined(separator: "\n")

            return "Failure to resolve endpoints:\n\(detailedErrorDescription)"

        case .setNetworkSettings:
            return "Failure to set network settings."

        case let .startWireGuardBackend(code):
            return "Failure to start WireGuard backend (error code: \(code))."
        }
    }
}