Skip to content

Commit b115fd6

Browse files
committed
chore: improve vpn configuration errors
1 parent e2e49a0 commit b115fd6

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum NetworkExtensionState: Equatable {
1616
case .disabled:
1717
"NetworkExtension tunnel disabled"
1818
case let .failed(error):
19-
"NetworkExtension config failed: \(error)"
19+
"NetworkExtension: \(error)"
2020
}
2121
}
2222
}
@@ -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,9 @@ 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(
64+
"Failed to save configuration: \(error.localizedDescription). Try logging in and out again."
65+
)
6466
}
6567
}
6668

@@ -71,17 +73,24 @@ extension CoderVPNService {
7173
try await tunnel.removeFromPreferences()
7274
}
7375
} catch {
74-
throw .internalError("couldn't remove tunnels: \(error)")
76+
throw .internalError(error.localizedDescription)
7577
}
7678
}
7779

7880
func startTunnel() async {
81+
let tm: NETunnelProviderManager
82+
do {
83+
tm = try await getTunnelManager()
84+
} catch {
85+
logger.error("get tunnel: \(error)")
86+
neState = .failed("Failed to get VPN configuration: \(error.description)")
87+
return
88+
}
7989
do {
80-
let tm = try await getTunnelManager()
8190
try tm.connection.startVPNTunnel()
8291
} catch {
8392
logger.error("start tunnel: \(error)")
84-
neState = .failed(error.localizedDescription)
93+
neState = .failed("Failed to start VPN tunnel: \(error.localizedDescription)")
8594
return
8695
}
8796
logger.debug("started tunnel")
@@ -94,7 +103,7 @@ extension CoderVPNService {
94103
tm.connection.stopVPNTunnel()
95104
} catch {
96105
logger.error("stop tunnel: \(error)")
97-
neState = .failed(error.localizedDescription)
106+
neState = .failed("Failed to stop VPN tunnel: \(error.localizedDescription)")
98107
return
99108
}
100109
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
}

Coder-Desktop/project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ packages:
9898
# - Set onAppear/disappear handlers.
9999
# The upstream repo has a purposefully limited API
100100
url: https://github.com/coder/fluid-menu-bar-extra
101-
revision: 8e1d8b8
101+
revision: b0d5438
102102
KeychainAccess:
103103
url: https://github.com/kishikawakatsumi/KeychainAccess
104104
branch: e0c7eebc5a4465a3c4680764f26b7a61f567cdaf

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy