Skip to content

chore: improve vpn configuration errors #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Coder-Desktop/Coder-Desktop/VPN/NetworkExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum NetworkExtensionState: Equatable {
case .disabled:
"NetworkExtension tunnel disabled"
case let .failed(error):
"NetworkExtension config failed: \(error)"
"NetworkExtension: \(error)"
}
}
}
Expand Down Expand Up @@ -44,7 +44,7 @@ extension CoderVPNService {
try await removeNetworkExtension()
} catch {
logger.error("remove tunnel failed: \(error)")
neState = .failed(error.localizedDescription)
neState = .failed("Failed to remove configuration: \(error.description)")
return
}
logger.debug("inserting new tunnel")
Expand All @@ -60,7 +60,9 @@ extension CoderVPNService {
} catch {
// This typically fails when the user declines the permission dialog
logger.error("save tunnel failed: \(error)")
neState = .failed("Failed to save tunnel: \(error.localizedDescription). Try logging in and out again.")
neState = .failed(
"Failed to save configuration: \(error.localizedDescription). Try logging in and out again."
)
}
}

Expand All @@ -71,17 +73,24 @@ extension CoderVPNService {
try await tunnel.removeFromPreferences()
}
} catch {
throw .internalError("couldn't remove tunnels: \(error)")
throw .internalError(error.localizedDescription)
}
}

func startTunnel() async {
let tm: NETunnelProviderManager
do {
tm = try await getTunnelManager()
} catch {
logger.error("get tunnel: \(error)")
neState = .failed("Failed to get VPN configuration: \(error.description)")
return
}
do {
let tm = try await getTunnelManager()
try tm.connection.startVPNTunnel()
} catch {
logger.error("start tunnel: \(error)")
neState = .failed(error.localizedDescription)
neState = .failed("Failed to start VPN tunnel: \(error.localizedDescription)")
return
}
logger.debug("started tunnel")
Expand All @@ -94,7 +103,7 @@ extension CoderVPNService {
tm.connection.stopVPNTunnel()
} catch {
logger.error("stop tunnel: \(error)")
neState = .failed(error.localizedDescription)
neState = .failed("Failed to stop VPN tunnel: \(error.localizedDescription)")
return
}
logger.debug("stopped tunnel")
Expand Down
10 changes: 5 additions & 5 deletions Coder-Desktop/Coder-Desktop/VPN/VPNService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum VPNServiceError: Error, Equatable {
case systemExtensionError(SystemExtensionState)
case networkExtensionError(NetworkExtensionState)

var description: String {
public var description: String {
switch self {
case let .internalError(description):
"Internal Error: \(description)"
Expand All @@ -48,7 +48,7 @@ enum VPNServiceError: Error, Equatable {
}
}

var localizedDescription: String { description }
public var localizedDescription: String { description }
}

@MainActor
Expand Down Expand Up @@ -126,13 +126,13 @@ final class CoderVPNService: NSObject, VPNService {
// this just configures the VPN, it doesn't enable it
tunnelState = .disabled
} else {
do {
do throws(VPNServiceError) {
try await removeNetworkExtension()
neState = .unconfigured
tunnelState = .disabled
} catch {
logger.error("failed to remove network extension: \(error)")
neState = .failed(error.localizedDescription)
logger.error("failed to remove configuration: \(error)")
neState = .failed("Failed to remove configuration: \(error.description)")
}
}
}
Expand Down
Loading