From 3dd0f3a1548ac05b019f578a16cea69438f0bfe1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 24 Jul 2024 20:42:35 -0700 Subject: [PATCH] Report DraftsPersistentContainer initializer errors to Sentry --- .../Sources/ComposeUI/CoreData/DraftsPersistentContainer.swift | 3 +++ Tusker/AppDelegate.swift | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftsPersistentContainer.swift b/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftsPersistentContainer.swift index a6c1342d..06c4679d 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftsPersistentContainer.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftsPersistentContainer.swift @@ -16,6 +16,8 @@ public class DraftsPersistentContainer: NSPersistentContainer { public static let shared = DraftsPersistentContainer() + public static var captureError: ((any Error) -> Void)? + private static let managedObjectModel: NSManagedObjectModel = { let url = Bundle.module.url(forResource: "Drafts", withExtension: "momd")! return NSManagedObjectModel(contentsOf: url)! @@ -39,6 +41,7 @@ public class DraftsPersistentContainer: NSPersistentContainer { loadPersistentStores { _, error in if let error { + DraftsPersistentContainer.captureError?(error) fatalError("Loading persistent store: \(error)") } } diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index c5da7928..374d7b78 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -56,6 +56,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // make sure the persistent container is initialized on the main thread // otherwise initializing it on the background thread can deadlock with accessing it on the main thread elsewhere + #if canImport(Sentry) + DraftsPersistentContainer.captureError = { SentrySDK.capture(error: $0) } + #endif _ = DraftsPersistentContainer.shared DispatchQueue.global(qos: .userInitiated).async {