Skip to content

Commit ed2f112

Browse files
authored
Use wpAssertionFailure in TaggedManagedObjectID (#24376)
* Use `wpAssertionFailure` to bypass app delegate in `TaggedManagedObjectID` * Replace call to app delegate with `wpAssertionFailure` After all, the goal of the code was to log the error, which `wpAssertionFailure` allows to do. Removing the app delegate access unblocks moving `TaggedManagedObjectID` away from the apps targets and into WordPressData.
1 parent b9bc67a commit ed2f112

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

WordPress/Classes/Utility/CoreData/TaggedManagedObjectID.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,13 @@ public struct TaggedManagedObjectID<Model: NSManagedObject>: Hashable {
3939
do {
4040
try context.obtainPermanentIDs(for: [object])
4141
} catch {
42-
// It should be okay to let the app crash when `obtainPermanentIDs` fails. Because, we crash the app
43-
// intentionally when `save()` fails (see the `ContextManager.internalSave` function). Also, if the
44-
// `obtainPermanentIDs` call fails (which may mean SQLite failing to update the database file),
45-
// then the save call followed (because we typically save newly added model objects) probably is going
46-
// to fail too. Finally, there aren't many save crashes on Sentry and `obtainPermanentIDs` should be
47-
// less likely to throw errors than `NSManagedObjectContext.save` function.
48-
//
49-
// However, just to be safe, we'll log and monitor this error (if it ever happens) for a few releases.
50-
// We can decide later if we'd like to change the assertion to a fatal error.
51-
WordPressAppDelegate.crashLogging?.logError(error)
52-
assertionFailure("Failed to obtain permanent id for \(objectID). Error: \(error)")
42+
wpAssertionFailure(
43+
"Failed to obtain permanent id from NSManagedObject.",
44+
userInfo: [
45+
"objectID": String(describing: objectID),
46+
"error": String(describing: error),
47+
]
48+
)
5349
}
5450
objectID = object.objectID
5551
}

0 commit comments

Comments
 (0)