diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 4a110837e..a464fa33e 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -344,8 +344,9 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { } for await result in group { - if case .failure = result { + if case .failure(let error) = result { errorOccurred = true + postSyncError(error, account: account) } } } @@ -384,7 +385,7 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { folder.externalID = externalID account.addFolderToTree(folder) - await withTaskGroup(of: Void.self) { group in + await withTaskGroup(of: Error?.self) { group in for feed in feedsToRestore { folder.topLevelFeeds.remove(feed) @@ -392,12 +393,20 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { do { try await self.restoreFeed(for: account, feed: feed, container: folder) await self.syncProgress.completeTask() + return nil } catch { Self.logger.error("CloudKit: Restore folder feed error: \(error.localizedDescription)") await self.syncProgress.completeTask() + return error } } } + + for await error in group { + if let error { + postSyncError(error, account: account) + } + } } account.addFolderToTree(folder) @@ -440,6 +449,9 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { try? await self.initialRefreshAll(for: account) } catch { Self.logger.error("CloudKitAccountDelegate: \(#function, privacy: .public) error: \(error.localizedDescription)") + if let account = self.account { + self.postSyncError(error, account: account) + } } } accountZone.subscribeToZoneChanges() @@ -696,6 +708,15 @@ private extension CloudKitAccountDelegate { } } + func postSyncError(_ error: Error, account: Account) { + let userInfo: [String: Any] = [ + Account.UserInfoKey.syncError: error, + Account.UserInfoKey.accountName: account.nameForDisplay, + Account.UserInfoKey.accountType: account.type.rawValue + ] + NotificationCenter.default.post(name: .AccountDidEncounterSyncError, object: self, userInfo: userInfo) + } + func storeArticleChanges(new: Set
?, updated: Set
?, deleted: Set
?) async { // New records with a read status aren't really new, they just didn't have the read article stored Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)")