Fixes “Check for Updates” not updating any sources if one source fails

This commit is contained in:
Riley Testut
2023-05-29 18:15:16 -05:00
committed by Magesh K
parent e03813c19e
commit f5b63b52b4

View File

@@ -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
{