Improve CoreData error reporting
This commit is contained in:
parent
b38c24b347
commit
38b0d57118
|
@ -72,12 +72,27 @@ class MastodonCachePersistentStore: NSPersistentContainer {
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
try context.save()
|
try context.save()
|
||||||
} catch {
|
} catch let error as NSError {
|
||||||
logger.error("Unable to save managed object context: \(String(describing: error), privacy: .public)")
|
logger.error("Unable to save managed object context: \(String(describing: error), privacy: .public)")
|
||||||
let crumb = Breadcrumb(level: .fatal, category: "PersistentStore")
|
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)
|
SentrySDK.addBreadcrumb(crumb: crumb)
|
||||||
fatalError("Unable to save managed object context")
|
fatalError("Unable to save managed object context: \(String(describing: error))")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue