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

Improves underlying error pixel information #2543

Merged
merged 6 commits into from
Apr 8, 2024

Conversation

diegoreymendez
Copy link
Contributor

Task/Issue URL: https://app.asana.com/0/0/1206999233882390/f

Description

Some errors have more than 1 level of underlying error information. I've added code to handle this specifically in a way that we support including multiple levels of underlying errors, to get more detailed information.

Additionally I'm doing some cleanup work to remove unnecessary code and start reducing debt.

Testing

  1. Make sure CI is green - I've added a unit test to report multiple levels of underlying error info.

Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

@diegoreymendez diegoreymendez self-assigned this Apr 4, 2024
@github-actions github-actions bot added the bot: not in app board Added by automation for pull requests with tasks not added to macOS App Board Asana project label Apr 4, 2024
@@ -19,15 +19,17 @@
import Foundation
import PixelKit

extension TransparentProxyController.StartError: PixelKitEventErrorDetails {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PixelKitEventErrorDetails was never needed and is now replaced by the more standard CustomNSError.

params[PixelKit.Parameters.underlyingErrorDomain] = underlyingError.domain
let underlyingErrorParameters = self.underlyingErrorParameters(for: nsError)
params.merge(underlyingErrorParameters) { first, _ in
return first
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of supporting only 1 level of underlying error info, we now support multiple in order to get all the detail.

Comment on lines +117 to +118
let errorCodeParameterName = PixelKit.Parameters.underlyingErrorCode + (level == 0 ? "" : String(level + 1))
let errorDomainParameterName = PixelKit.Parameters.underlyingErrorDomain + (level == 0 ? "" : String(level + 1))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First underlying error params are named as usual "ue" and "ud". Follow up underlying errors are named "ue2", "ue3", etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Comment on lines -378 to +379
let nsError = error as NSError

self[PixelKit.Parameters.errorCode] = "\(nsError.code)"
self[PixelKit.Parameters.errorDomain] = nsError.domain

if let error = error as? PixelKitEventErrorDetails,
let underlyingError = error.underlyingError {

let underlyingNSError = underlyingError as NSError
self[PixelKit.Parameters.underlyingErrorCode] = "\(underlyingNSError.code)"
self[PixelKit.Parameters.underlyingErrorDomain] = underlyingNSError.domain
} else if let underlyingError = nsError.userInfo["NSUnderlyingError"] as? NSError {
self[PixelKit.Parameters.underlyingErrorCode] = "\(underlyingError.code)"
self[PixelKit.Parameters.underlyingErrorDomain] = underlyingError.domain
} else if let sqlErrorCode = nsError.userInfo["NSSQLiteErrorDomain"] as? NSNumber {
self[PixelKit.Parameters.underlyingErrorCode] = "\(sqlErrorCode.intValue)"
self[PixelKit.Parameters.underlyingErrorDomain] = "NSSQLiteErrorDomain"
self.merge(error.pixelParameters) { _, second in
return second
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was duplicated code, so now I've unified to use error.pixelParameters.

Comment on lines -51 to -69
extension PixelKitEventV2 {
var pixelParameters: [String: String] {
guard let error else {
return [:]
}

let nsError = error as NSError
var parameters = [
PixelKit.Parameters.errorCode: "\(nsError.code)",
PixelKit.Parameters.errorDomain: nsError.domain,
]

if let error = error as? PixelKitEventErrorDetails {
parameters.merge(error.underlyingErrorParameters, uniquingKeysWith: { $1 })
}

return parameters
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was duplicated code, we're now using error.pixelParameters.

var customFields: [String: String]?

/// Convenience initializer for cleaner semantics
///
public static func expect(pixelName: String, error: Error? = nil, underlyingError: Error? = nil, customFields: [String: String]? = nil) -> PixelFireExpectations {
public static func expect(pixelName: String, error: Error? = nil, underlyingErrors: [Error] = [], customFields: [String: String]? = nil) -> PixelFireExpectations {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this test utility to support multiple levels of underlying errors.

@@ -78,7 +78,7 @@ final class NetworkProtectionPixelEventTests: XCTestCase {
fire(NetworkProtectionPixelEvent.networkProtectionControllerStartFailure(TestError.testError),
and: .expect(pixelName: "m_mac_netp_controller_start_failure",
error: TestError.testError,
underlyingError: TestError.underlyingError),
underlyingErrors: [TestError.underlyingError]),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adapting existing tests to the new testing utility changes.

@diegoreymendez diegoreymendez marked this pull request as ready for review April 4, 2024 11:22
@diegoreymendez diegoreymendez removed the bot: not in app board Added by automation for pull requests with tasks not added to macOS App Board Asana project label Apr 4, 2024
@diegoreymendez diegoreymendez requested a review from samsymons April 4, 2024 11:24
Copy link
Collaborator

@samsymons samsymons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice changes here, LGTM!

@diegoreymendez diegoreymendez merged commit 553d3ee into main Apr 8, 2024
17 checks passed
@diegoreymendez diegoreymendez deleted the diego/multilevel-underlying-error-information branch April 8, 2024 07:57
@diegoreymendez
Copy link
Contributor Author

Thank you, sir!

samsymons added a commit that referenced this pull request Apr 8, 2024
* main: (22 commits)
  Removes last instance of NETWORK_PROTECTION flag (#2573)
  Bye bye NETWORK_PROTECTION (#2509)
  QWD: Enable Hide/Show for Autofill Credit Card Number and CVV (#2539)
  Removed the VPN waitlist beta pixels (#2555)
  VPN: Cleanup authorize call (#2565)
  Revert "VPN: Cleanup authorize call (#2553)"
  VPN: Cleanup authorize call (#2553)
  Improves underlying error pixel information (#2543)
  Fixes the VPN restarting logic on update (#2545)
  fix download save panel disappearing on navigation (#2549)
  Add CI support for handling installation attribution (#2502)
  Fix usertext comment to ensure it matches localizable string (#2546)
  Update Neighbor Report (#2542)
  DBP: Compare by url and not name (#2544)
  Adds a series of UI tests for Bookmarks Bar visibility
  Improve Handling of noData Import Errors (#2494)
  Use the default action button style for VPN onboarding (#2529)
  Closing empty tabs after download (#2510)
  Add Web UI loading state pixels (#2531)
  fix localization warnings (#2288)
  ...
samsymons added a commit that referenced this pull request Apr 8, 2024
…flagger

# By Diego Rey Mendez (7) and others
# Via GitHub
* main:
  Automatically close VPN popover when the app goes into the background (#2562)
  Fix last known VPN crash and missing IPC registration (#2579)
  Create a new window when making a feedback form if necessary (#2563)
  Improve VPN uninstallation reliability (#2560)
  Removes last instance of NETWORK_PROTECTION flag (#2573)
  Bye bye NETWORK_PROTECTION (#2509)
  QWD: Enable Hide/Show for Autofill Credit Card Number and CVV (#2539)
  Removed the VPN waitlist beta pixels (#2555)
  VPN: Cleanup authorize call (#2565)
  Revert "VPN: Cleanup authorize call (#2553)"
  VPN: Cleanup authorize call (#2553)
  Improves underlying error pixel information (#2543)

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants