Ways SwiftData’s ModelContainer Can Error on Creation
Here’s what I see from a typical report from a crashing user device. The first thing that jumps out is that there is no explanation from the
SwiftData
error itself.[…]
But thankfully, we have the logs to look through. In this example, there are a few
level=Error
logs fromcom.apple.coredata
that look promising[…][…]
Looking through similar reports I have received so far, I can see a few distinct crash reasons
- Error due to schema mismatch (this is the example we reviewed above)
- Error due to no free space on disk
- Error due to multiple migrators attempting to migrate the database concurrently
Core Data has always logged more helpful information than it returns back in the NSError
, but at least it usually gives you a reasonable error code. (They aren’t all listed in the documentation; see CoreDataErrors.h and FoundationErrors.h.) Swift has fancy error handling, but somehow the new framework bundles these disparate failures into a generic loadIssueModelContainer error with no associated information.
Previously: