Skip to content

Commit

Permalink
Send pixel on sync secure storage read failure (#1058)
Browse files Browse the repository at this point in the history
<!--
Note: This checklist is a reminder of our shared engineering
expectations.
-->

Please review the release process for BrowserServicesKit
[here](https://app.asana.com/0/1200194497630846/1200837094583426).

**Required**:

Task/Issue URL:
https://app.asana.com/0/1201493110486074/1208686320819590/f
iOS PR: duckduckgo/iOS#3530
macOS PR: duckduckgo/macos-browser#3497
What kind of version bump will this require?: Minor

**Description:**

On investigating a hard-to-reproduce issue with sync, I noticed there's
a gap in error reporting when the secure storage (keychain) is not
available. This adds a pixel for that case.

**Steps to test this PR:**
Just a pixel in an error case. Hard to test without altering code. But
if you do want to do that:

Enable sync
Change BSK.DDGSync.SecureStorage.account() to throw every time
Go to the Settings -> Sync screen
You should see the `sync_secure_storage_read_error` Pixel in the debug
console

**OS Testing**:

* [ ] iOS 14
* [ ] iOS 15
* [ ] iOS 16
* [ ] macOS 10.15
* [ ] macOS 11
* [ ] macOS 12

---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
  • Loading branch information
graeme authored Nov 5, 2024
1 parent 19f1e5c commit 56dbee7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/DDGSync/DDGSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ public class DDGSync: DDGSyncing {
}

public var account: SyncAccount? {
try? dependencies.secureStore.account()
do {
return try dependencies.secureStore.account()
} catch {
if let syncError = error as? SyncError {
dependencies.errorEvents.fire(syncError, error: syncError)
}
return nil
}
}

public var scheduler: Scheduling {
Expand Down
10 changes: 10 additions & 0 deletions Sources/DDGSync/SyncError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,14 @@ extension SyncError: CustomNSError {
}
}

public var errorUserInfo: [String: Any] {
switch self {
case .failedToReadSecureStore(let status), .failedToWriteSecureStore(let status), .failedToRemoveSecureStore(let status):
let underlyingError = NSError(domain: "secError", code: Int(status))
return [NSUnderlyingErrorKey: underlyingError]
default:
return [:]
}
}

}

0 comments on commit 56dbee7

Please sign in to comment.