diff --git a/kDriveCore/Utils/PHAsset/PHAsset+Exension.swift b/kDriveCore/Utils/PHAsset/PHAsset+Exension.swift index 4d38843a2..f96959ceb 100644 --- a/kDriveCore/Utils/PHAsset/PHAsset+Exension.swift +++ b/kDriveCore/Utils/PHAsset/PHAsset+Exension.swift @@ -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 { @@ -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 } diff --git a/kDriveCore/Utils/PHAsset/PHAssetIdentifier.swift b/kDriveCore/Utils/PHAsset/PHAssetIdentifier.swift index 6cf0ad2d8..bec25044b 100644 --- a/kDriveCore/Utils/PHAsset/PHAssetIdentifier.swift +++ b/kDriveCore/Utils/PHAsset/PHAssetIdentifier.swift @@ -147,7 +147,6 @@ struct PHAssetIdentifier: PHAssetIdentifiable { let activity = ExpiringActivity(id: uid, delegate: activityDelegate) activity.start() - // TODO: Check iCloud behaviour let options = PHAssetResourceRequestOptions() options.isNetworkAccessAllowed = true options.progressHandler = { progress in @@ -155,10 +154,17 @@ struct PHAssetIdentifier: PHAssetIdentifiable { } group.enter() + var resourceManagerError: Error? PHAssetResourceManager.default().requestData(for: bestResource, options: options) { data in hasher.update(data) - } completionHandler: { _ in + } completionHandler: { error in + if let error { + resourceManagerError = error + Log.photoLibraryUploader("hashing resource failed with \(error)", level: .error) + } else { + Log.photoLibraryUploader("hashing resource finished successfully") + } hasher.finalize() group.leave() } @@ -166,13 +172,18 @@ struct PHAssetIdentifier: PHAssetIdentifiable { activity.endAll() - guard let error = activityDelegate.error else { - // All good - return hasher.digestString + // PHAssetResourceManager errors, possibly fetching an asset on iCloud failed + if let resourceManagerError { + SentryDebug.capturePHAssetResourceManagerError(resourceManagerError) + throw resourceManagerError } // The processing of the hash was interrupted by the system - throw error + if let activityError = activityDelegate.error { + throw activityError + } + + return hasher.digestString } } } diff --git a/kDriveCore/Utils/Sentry/SentryDebug+Upload.swift b/kDriveCore/Utils/Sentry/SentryDebug+Upload.swift index 8f1a30cee..d3c6d6fbe 100644 --- a/kDriveCore/Utils/Sentry/SentryDebug+Upload.swift +++ b/kDriveCore/Utils/Sentry/SentryDebug+Upload.swift @@ -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]) { diff --git a/kDriveCore/Utils/Sentry/SentryDebug.swift b/kDriveCore/Utils/Sentry/SentryDebug.swift index d5ea45f63..cbe58fb94 100644 --- a/kDriveCore/Utils/Sentry/SentryDebug.swift +++ b/kDriveCore/Utils/Sentry/SentryDebug.swift @@ -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) {