summaryrefslogtreecommitdiffhomepage
path: root/ios/PacketTunnel/WireGuardAdapter/WireGuardAdapterError+Localization.swift
blob: 39961e5f3fdeb7939deba523d86dbbfe75b06dee (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
41
42
43
44
45
46
47
48
49
50
51
52
53
//
//  WireGuardAdapterError+Localization.swift
//  PacketTunnel
//
//  Created by pronebird on 14/07/2022.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import WireGuardKit

struct WireGuardAdapterErrorWrapper: LocalizedError {
    let error: WireGuardAdapterError

    public var errorDescription: String? {
        switch error {
        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))."
        case .noInterfaceIp:
            return "Interface has no IP address specified."
        case .noSuchTunnel:
            return "No such WireGuard tunnel"
        case .noTunnelVirtualInterface:
            return "Tunnel has no virtual (IAN) interface"
        case .icmpSocketNotOpen:
            return "ICMP socket not open"
        case let .internalError(code):
            return "Internal error \(code)"
        }
    }
}