Skip to content
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

Improve VPN underlying error detail #806

Merged
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
21 changes: 21 additions & 0 deletions Sources/NetworkProtection/Networking/NetworkProtectionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ public enum NetworkProtectionClientError: CustomNSError, NetworkProtectionErrorC
case .accessDenied: return 13
}
}

public var errorUserInfo: [String: Any] {
switch self {
case .failedToFetchLocationList(let error),
.failedToParseLocationListResponse(let error),
.failedToFetchServerList(let error),
.failedToParseServerListResponse(let error),
.failedToFetchRegisteredServers(let error),
.failedToParseRegisteredServersResponse(let error),
.failedToRedeemInviteCode(let error),
.failedToParseRedeemResponse(let error):
return [NSUnderlyingErrorKey: error as NSError]
case .failedToEncodeRegisterKeyRequest,
.failedToEncodeRedeemRequest,
.invalidInviteCode,
.failedToRetrieveAuthToken,
.invalidAuthToken,
.accessDenied:
return [:]
}
}
}

struct RegisterKeyRequestBody: Encodable {
Expand Down
31 changes: 30 additions & 1 deletion Sources/NetworkProtection/WireGuardKit/WireGuardAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum WireGuardAdapterErrorInvalidStateReason: String {
case updatedTunnelWhileStopped
}

public enum WireGuardAdapterError: Error {
public enum WireGuardAdapterError: CustomNSError {
/// Failure to locate tunnel file descriptor.
case cannotLocateTunnelFileDescriptor

Expand All @@ -28,6 +28,35 @@ public enum WireGuardAdapterError: Error {

/// Failure to start WireGuard backend.
case startWireGuardBackend(Int32)

public var errorCode: Int {
switch self {
case .cannotLocateTunnelFileDescriptor: return 100
case .invalidState: return 101
case .dnsResolution: return 102
case .setNetworkSettings: return 103
case .startWireGuardBackend: return 104
}
}

public var errorUserInfo: [String: Any] {
switch self {
case .cannotLocateTunnelFileDescriptor,
.invalidState:
return [:]
case .dnsResolution(let errors):
guard let firstError = errors.first else {
return [:]
}

return [NSUnderlyingErrorKey: firstError as NSError]
case .setNetworkSettings(let error):
return [NSUnderlyingErrorKey: error as NSError]
case .startWireGuardBackend(let code):
let error = NSError(domain: "startWireGuardBackend", code: Int(code))
return [NSUnderlyingErrorKey: error as NSError]
}
}
}

/// Enum representing internal state of the `WireGuardAdapter`
Expand Down
Loading