@@ -43,45 +43,26 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
43
43
return nil
44
44
}
45
45
46
- // swiftlint:disable:next function_body_length
47
46
override func startTunnel(
48
47
options _: [ String : NSObject ] ? , completionHandler: @escaping ( Error ? ) -> Void
49
48
) {
50
49
logger. info ( " startTunnel called " )
51
50
guard manager == nil else {
52
51
logger. error ( " startTunnel called with non-nil Manager " )
53
- completionHandler (
54
- NSError (
55
- domain: " \( Bundle . main. bundleIdentifier!) .PTP " ,
56
- code: - 1 ,
57
- userInfo: [ NSLocalizedDescriptionKey: " Already running " ]
58
- )
59
- )
52
+ completionHandler ( makeNSError ( suffix: " PTP " , desc: " Already running " ) )
60
53
return
61
54
}
62
55
guard let proto = protocolConfiguration as? NETunnelProviderProtocol ,
63
56
let baseAccessURL = proto. serverAddress
64
57
else {
65
58
logger. error ( " startTunnel called with nil protocolConfiguration " )
66
- completionHandler (
67
- NSError (
68
- domain: " \( Bundle . main. bundleIdentifier!) .PTP " ,
69
- code: - 1 ,
70
- userInfo: [ NSLocalizedDescriptionKey: " Missing Configuration " ]
71
- )
72
- )
59
+ completionHandler ( makeNSError ( suffix: " PTP " , desc: " Missing Configuration " ) )
73
60
return
74
61
}
75
62
// HACK: We can't write to the system keychain, and the NE can't read the user keychain.
76
63
guard let token = proto. providerConfiguration ? [ " token " ] as? String else {
77
64
logger. error ( " startTunnel called with nil token " )
78
- completionHandler (
79
- NSError (
80
- domain: " \( Bundle . main. bundleIdentifier!) .PTP " ,
81
- code: - 1 ,
82
- userInfo: [ NSLocalizedDescriptionKey: " Missing Token " ]
83
- )
84
- )
65
+ completionHandler ( makeNSError ( suffix: " PTP " , desc: " Missing Token " ) )
85
66
return
86
67
}
87
68
logger. debug ( " retrieved token & access URL " )
@@ -104,11 +85,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
104
85
} catch {
105
86
logger. error ( " error starting manager: \( error. description, privacy: . public) " )
106
87
completionHandler (
107
- NSError (
108
- domain: " \( Bundle . main. bundleIdentifier!) .Manager " ,
109
- code: - 1 ,
110
- userInfo: [ NSLocalizedDescriptionKey: error. description]
111
- )
88
+ makeNSError ( suffix: " Manager " , desc: error. description)
112
89
)
113
90
}
114
91
}
0 commit comments