diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index 391eca44..4011fab4 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -1502,40 +1502,46 @@ private extension MyAppsViewController } } - let (_, context) = try await result - - try await context.performAsync { + do + { do { - try context.save() + let (_, context) = try await result + + try await context.performAsync { + try context.save() + } } catch let error as AppManager.FetchSourcesError { - try error.managedObjectContext?.save() - throw error - } - catch let mergeError as MergeError - { - guard let sourceID = mergeError.sourceID else { throw mergeError } - - let sanitizedError = (mergeError as NSError).sanitizedForSerialization() - DatabaseManager.shared.persistentContainer.performBackgroundTask { context in - do - { - guard let source = Source.first(satisfying: NSPredicate(format: "%K == %@", #keyPath(Source.identifier), sourceID), in: context) else { return } - - source.error = sanitizedError - try context.save() - } - catch - { - print("[ALTLog] Failed to assign error \(sanitizedError.localizedErrorCode) to source \(sourceID).", error) - } + try await error.managedObjectContext?.performAsync { + try error.managedObjectContext?.save() } - throw mergeError + throw error } } + catch let mergeError as MergeError + { + guard let sourceID = mergeError.sourceID else { throw mergeError } + + let sanitizedError = (mergeError as NSError).sanitizedForSerialization() + DatabaseManager.shared.persistentContainer.performBackgroundTask { context in + do + { + guard let source = Source.first(satisfying: NSPredicate(format: "%K == %@", #keyPath(Source.identifier), sourceID), in: context) else { return } + + source.error = sanitizedError + try context.save() + } + catch + { + print("[ALTLog] Failed to assign error \(sanitizedError.localizedErrorCode) to source \(sourceID).", error) + } + } + + throw mergeError + } } catch let error as NSError {