-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WireGuard NetP Error Pixels (#508)
* Add device manager stuff * Extract errors to own file * Add mapping of wireguard errors * Propogate converted WireguardAdapterErrors * Fix comment * Fix bad merge * Disable pinger test
- Loading branch information
Showing
6 changed files
with
139 additions
and
70 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
Sources/NetworkProtection/Diagnostics/NetworkProtectionError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// NetworkProtectionError.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2023 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol NetworkProtectionErrorConvertible { | ||
var networkProtectionError: NetworkProtectionError { get } | ||
} | ||
|
||
public enum NetworkProtectionError: LocalizedError { | ||
// Tunnel configuration errors | ||
case noServerRegistrationInfo | ||
case couldNotSelectClosestServer | ||
case couldNotGetPeerPublicKey | ||
case couldNotGetPeerHostName | ||
case couldNotGetInterfaceAddressRange | ||
|
||
// Client errors | ||
case failedToFetchServerList(Error?) | ||
case failedToParseServerListResponse(Error) | ||
case failedToEncodeRegisterKeyRequest | ||
case failedToFetchRegisteredServers(Error?) | ||
case failedToParseRegisteredServersResponse(Error) | ||
case failedToEncodeRedeemRequest | ||
case invalidInviteCode | ||
case failedToRedeemInviteCode(Error?) | ||
case failedToParseRedeemResponse(Error) | ||
case invalidAuthToken | ||
case serverListInconsistency | ||
|
||
// Server list store errors | ||
case failedToEncodeServerList(Error) | ||
case failedToDecodeServerList(Error) | ||
case failedToWriteServerList(Error) | ||
case noServerListFound | ||
case couldNotCreateServerListDirectory(Error) | ||
case failedToReadServerList(Error) | ||
|
||
// Keychain errors | ||
case failedToCastKeychainValueToData(field: String) | ||
case keychainReadError(field: String, status: Int32) | ||
case keychainWriteError(field: String, status: Int32) | ||
case keychainDeleteError(status: Int32) | ||
|
||
// Wireguard errors | ||
case wireGuardCannotLocateTunnelFileDescriptor | ||
case wireGuardInvalidState | ||
case wireGuardDnsResolution | ||
case wireGuardSetNetworkSettings(Error) | ||
case startWireGuardBackend(Int32) | ||
|
||
// Auth errors | ||
case noAuthTokenFound | ||
|
||
// Unhandled error | ||
case unhandledError(function: String, line: Int, error: Error) | ||
|
||
public var errorDescription: String? { | ||
// This is probably not the most elegant error to show to a user but | ||
// it's a great way to get detailed reports for those cases we haven't | ||
// provided good descriptions for yet. | ||
return "NetworkProtectionError.\(String(describing: self))" | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...tworkProtection/Diagnostics/WireGuardAdapterError+NetworkProtectionErrorConvertible.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// WireguardAdapterError+NetworkProtectionErrorConvertible.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2023 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
extension WireGuardAdapterError: NetworkProtectionErrorConvertible { | ||
var networkProtectionError: NetworkProtectionError { | ||
switch self { | ||
case .cannotLocateTunnelFileDescriptor: | ||
return .wireGuardCannotLocateTunnelFileDescriptor | ||
case .invalidState: | ||
return .wireGuardInvalidState | ||
case .dnsResolution: | ||
return .wireGuardDnsResolution | ||
case .setNetworkSettings(let error): | ||
return .wireGuardSetNetworkSettings(error) | ||
case .startWireGuardBackend(let code): | ||
return .startWireGuardBackend(code) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters