Skip to content

Commit

Permalink
feat: PHAssetResourceManager errors while fetching an asset are sent …
Browse files Browse the repository at this point in the history
…to Sentry to create a dashboard.
  • Loading branch information
adrien-coye committed Nov 8, 2024
1 parent c41de10 commit c72428a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kDriveCore/Utils/PHAsset/PHAsset+Exension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public extension PHAsset {
shouldTransformIntoJPEG = true
}

// Asset are copied when we start the Upload, thus guarantees the stability of the file
// Asset is copied when we start the Upload, thus guarantees the stability of the file
@InjectService var fileImportHelper: FileImportHelper
let targetURL = fileImportHelper.generateImportURL(for: resourceUTI)
do {
Expand All @@ -149,6 +149,7 @@ public extension PHAsset {
return targetURL
} catch {
SentryDebug.addBreadcrumb(message: error.localizedDescription, category: SentryDebug.Category.PHAsset, level: .error)
SentryDebug.capturePHAssetResourceManagerError(error)
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions kDriveCore/Utils/PHAsset/PHAssetIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ struct PHAssetIdentifier: PHAssetIdentifiable {

// PHAssetResourceManager errors, possibly fetching an asset on iCloud failed
if let resourceManagerError {
SentryDebug.capturePHAssetResourceManagerError(resourceManagerError)
throw resourceManagerError
}

Expand Down
9 changes: 9 additions & 0 deletions kDriveCore/Utils/Sentry/SentryDebug+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ extension SentryDebug {
SentryDebug.capture(message: EventNames.uploadCompletedSuccess, extras: metadata)
}

static func capturePHAssetResourceManagerError(_ error: Error, function: StaticString = #function) {
let metadata: [String: Any] = [
"func": function,
"error": error,
"localizedError": error.localizedDescription
]
SentryDebug.capture(message: ErrorNames.assetResourceManagerError, context: metadata, level: .error)
}

// MARK: - Upload notifications

static func uploadNotificationError(_ metadata: [String: Any]) {
Expand Down
2 changes: 2 additions & 0 deletions kDriveCore/Utils/Sentry/SentryDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public enum SentryDebug {
static let uploadSessionErrorHandling = "UploadSessionErrorHandling"
static let uploadErrorUserNotification = "UploadErrorUserNotification"
static let viewModelNotConnectedToView = "ViewModelNotConnected"
/// An error was generated by an instance of `PHAssetResourceManager`
static let assetResourceManagerError = "PHAssetResourceManagerError"
}

static func logTokenMigration(newToken: ApiToken, oldToken: ApiToken) {
Expand Down

0 comments on commit c72428a

Please sign in to comment.