Skip to content

Commit 2606a39

Browse files
committed
chore: improve vpn configuration errors
1 parent faaa0af commit 2606a39

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

Coder-Desktop/Coder-Desktop/VPN/NetworkExtension.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension CoderVPNService {
4444
try await removeNetworkExtension()
4545
} catch {
4646
logger.error("remove tunnel failed: \(error)")
47-
neState = .failed(error.localizedDescription)
47+
neState = .failed("Failed to remove configuration: \(error.description)")
4848
return
4949
}
5050
logger.debug("inserting new tunnel")
@@ -60,7 +60,7 @@ extension CoderVPNService {
6060
} catch {
6161
// This typically fails when the user declines the permission dialog
6262
logger.error("save tunnel failed: \(error)")
63-
neState = .failed("Failed to save tunnel: \(error.localizedDescription). Try logging in and out again.")
63+
neState = .failed("Failed to save configuration: \(error.localizedDescription). Try logging in and out again.")
6464
}
6565
}
6666

@@ -71,17 +71,24 @@ extension CoderVPNService {
7171
try await tunnel.removeFromPreferences()
7272
}
7373
} catch {
74-
throw .internalError("couldn't remove tunnels: \(error)")
74+
throw .internalError(error.localizedDescription)
7575
}
7676
}
7777

7878
func startTunnel() async {
79+
let tm: NETunnelProviderManager
80+
do {
81+
tm = try await getTunnelManager()
82+
} catch {
83+
logger.error("get tunnel: \(error)")
84+
neState = .failed("Failed to get VPN configuration: \(error.description)")
85+
return
86+
}
7987
do {
80-
let tm = try await getTunnelManager()
8188
try tm.connection.startVPNTunnel()
8289
} catch {
8390
logger.error("start tunnel: \(error)")
84-
neState = .failed(error.localizedDescription)
91+
neState = .failed("Failed to start VPN tunnel: \(error.localizedDescription)")
8592
return
8693
}
8794
logger.debug("started tunnel")
@@ -94,7 +101,7 @@ extension CoderVPNService {
94101
tm.connection.stopVPNTunnel()
95102
} catch {
96103
logger.error("stop tunnel: \(error)")
97-
neState = .failed(error.localizedDescription)
104+
neState = .failed("Failed to stop VPN tunnel: \(error.localizedDescription)")
98105
return
99106
}
100107
logger.debug("stopped tunnel")

Coder-Desktop/Coder-Desktop/VPN/VPNService.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum VPNServiceError: Error, Equatable {
3737
case systemExtensionError(SystemExtensionState)
3838
case networkExtensionError(NetworkExtensionState)
3939

40-
var description: String {
40+
public var description: String {
4141
switch self {
4242
case let .internalError(description):
4343
"Internal Error: \(description)"
@@ -48,7 +48,7 @@ enum VPNServiceError: Error, Equatable {
4848
}
4949
}
5050

51-
var localizedDescription: String { description }
51+
public var localizedDescription: String { description }
5252
}
5353

5454
@MainActor
@@ -126,13 +126,13 @@ final class CoderVPNService: NSObject, VPNService {
126126
// this just configures the VPN, it doesn't enable it
127127
tunnelState = .disabled
128128
} else {
129-
do {
129+
do throws(VPNServiceError) {
130130
try await removeNetworkExtension()
131131
neState = .unconfigured
132132
tunnelState = .disabled
133133
} catch {
134-
logger.error("failed to remove network extension: \(error)")
135-
neState = .failed(error.localizedDescription)
134+
logger.error("failed to remove configuration: \(error)")
135+
neState = .failed("Failed to remove configuration: \(error.description)")
136136
}
137137
}
138138
}

0 commit comments

Comments
 (0)