diff --git a/Tusker/CoreData/MastodonCachePersistentStore.swift b/Tusker/CoreData/MastodonCachePersistentStore.swift index 346f0e36..5910a7ea 100644 --- a/Tusker/CoreData/MastodonCachePersistentStore.swift +++ b/Tusker/CoreData/MastodonCachePersistentStore.swift @@ -72,12 +72,27 @@ class MastodonCachePersistentStore: NSPersistentContainer { } do { try context.save() - } catch { + } catch let error as NSError { logger.error("Unable to save managed object context: \(String(describing: error), privacy: .public)") let crumb = Breadcrumb(level: .fatal, category: "PersistentStore") - crumb.message = String(describing: error) + // note: NSDetailedErrorsKey == "NSDetailedErrorsKey" != "NSDetailedErrors" + if let detailed = error.userInfo["NSDetailedErrors"] as? [NSError] { + crumb.data = [ + "errors": detailed.compactMap { error -> [String: Any?]? in + guard let object = error.userInfo[NSValidationObjectErrorKey] as? NSManagedObject else { + return nil + } + return [ + "entity": object.entity.name, + "key": error.userInfo[NSValidationKeyErrorKey], + "value": error.userInfo[NSValidationValueErrorKey], + "message": error.localizedDescription, + ] + } + ] + } SentrySDK.addBreadcrumb(crumb: crumb) - fatalError("Unable to save managed object context") + fatalError("Unable to save managed object context: \(String(describing: error))") } }