@@ -43,45 +43,26 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
4343 return nil
4444 }
4545
46- // swiftlint:disable:next function_body_length
4746 override func startTunnel(
4847 options _: [ String : NSObject ] ? , completionHandler: @escaping ( Error ? ) -> Void
4948 ) {
5049 logger. info ( " startTunnel called " )
5150 guard manager == nil else {
5251 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 " ) )
6053 return
6154 }
6255 guard let proto = protocolConfiguration as? NETunnelProviderProtocol ,
6356 let baseAccessURL = proto. serverAddress
6457 else {
6558 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 " ) )
7360 return
7461 }
7562 // HACK: We can't write to the system keychain, and the NE can't read the user keychain.
7663 guard let token = proto. providerConfiguration ? [ " token " ] as? String else {
7764 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 " ) )
8566 return
8667 }
8768 logger. debug ( " retrieved token & access URL " )
@@ -104,11 +85,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
10485 } catch {
10586 logger. error ( " error starting manager: \( error. description, privacy: . public) " )
10687 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)
11289 )
11390 }
11491 }
0 commit comments