-
Notifications
You must be signed in to change notification settings - Fork 424
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
VPN: Specific TunnelController start failure reporting #2714
Merged
graeme
merged 6 commits into
release/7.115.0
from
graeme/add-more-specific-error-to-controller-failure
Apr 12, 2024
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
16be79e
Specific tunnelcontroller StartError reporting
graeme 6588a90
Remove silly comment
graeme 06238f0
Use auto domain for tunnelcontroller start error
graeme f265a34
Send underlying error with pixel
graeme 32cfb1f
Filter out permission denied errors
graeme 0e2dd0d
User underlying error key constant
graeme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -37,9 +37,24 @@ final class NetworkProtectionTunnelController: TunnelController { | |
|
||
// MARK: - Starting & Stopping the VPN | ||
|
||
enum StartError: LocalizedError { | ||
case connectionStatusInvalid | ||
enum StartError: LocalizedError, CustomNSError { | ||
case simulateControllerFailureError | ||
case loadFromPreferencesFailed(Error) | ||
case saveToPreferencesFailed(Error) | ||
case startVPNFailed(Error) | ||
case fetchAuthTokenFailed(Error) | ||
|
||
public static let errorDomain = "com.duckduckgo.NetworkProtectionTunnelController.StartError.domain" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note that I believe you can omit this, and the system will fill it in with a nice string. |
||
|
||
public var errorCode: Int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great to have explicit codes. Thanks :) |
||
switch self { | ||
case .simulateControllerFailureError: 0 | ||
case .loadFromPreferencesFailed: 1 | ||
case .saveToPreferencesFailed: 2 | ||
case .startVPNFailed: 3 | ||
case .fetchAuthTokenFailed: 4 | ||
} | ||
} | ||
} | ||
|
||
init() { | ||
|
@@ -147,7 +162,11 @@ final class NetworkProtectionTunnelController: TunnelController { | |
} | ||
|
||
options["activationAttemptId"] = UUID().uuidString as NSString | ||
options["authToken"] = try tokenStore.fetchToken() as NSString? | ||
do { | ||
options["authToken"] = try tokenStore.fetchToken() as NSString? | ||
} catch { | ||
throw StartError.fetchAuthTokenFailed(error) | ||
} | ||
options[NetworkProtectionOptionKey.selectedEnvironment] = VPNSettings(defaults: .networkProtectionGroupDefaults) | ||
.selectedEnvironment.rawValue as NSString | ||
|
||
|
@@ -161,7 +180,7 @@ final class NetworkProtectionTunnelController: TunnelController { | |
} | ||
} catch { | ||
Pixel.fire(pixel: .networkProtectionActivationRequestFailed, error: error) | ||
throw error | ||
throw StartError.startVPNFailed(error) | ||
} | ||
} | ||
|
||
|
@@ -203,26 +222,24 @@ final class NetworkProtectionTunnelController: TunnelController { | |
|
||
private func setupAndSave(_ tunnelManager: NETunnelProviderManager) async throws { | ||
setup(tunnelManager) | ||
try await tunnelManager.saveToPreferences() | ||
try await tunnelManager.loadFromPreferences() | ||
try await tunnelManager.saveToPreferences() | ||
try await saveToPreferences(tunnelManager) | ||
try await loadFromPreferences(tunnelManager) | ||
try await saveToPreferences(tunnelManager) | ||
} | ||
|
||
private func saveToPreferences(_ tunnelManager: NETunnelProviderManager) async throws { | ||
do { | ||
try await tunnelManager.saveToPreferences() | ||
} catch { | ||
Pixel.fire(pixel: .networkProtectionFailedToSaveToPreferences, error: error) | ||
throw error | ||
throw StartError.saveToPreferencesFailed(error) | ||
} | ||
} | ||
|
||
private func loadFromPreferences(_ tunnelManager: NETunnelProviderManager) async throws { | ||
do { | ||
try await tunnelManager.loadFromPreferences() | ||
} catch { | ||
Pixel.fire(pixel: .networkProtectionFailedToLoadFromPreferences, error: error) | ||
throw error | ||
throw StartError.loadFromPreferencesFailed(error) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!