SwiftData saying CoreData: error: Failed to stat path

This just started happening when installing my app on my phone and ipad. It still seems to work and the errors go away on the second installation, but it doesn't strike me as good.

The app has not been released yet.

When I remove the AppGroup, the error disappears. But I have a widget, so I need the AppGroup.

I've cleaned the build, deleted derived files, and rebooted many times.

I've deleted the app on the device and rebooted the device many times.

I've deleted the AppGroup in iCloud and then recreated it. I was really hoping that would work, but nope. I've created a new App Group and that didn't make a difference either.

So I'm stumped. Any thoughts on how to fix this?

thanks

CoreData: error: Failed to stat path '/private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application Support/default.store', errno 2 / No such file or directory.
CoreData: error: Executing as effective user 501
CoreData: error: Failed to statfs file; errno 2 / No such file or directory.
CoreData: error: Logging status information for directory path: /private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application Support
CoreData: error: Executing as effective user 501
....
error: URL: file:///private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application%20Support/default.store
error: <NSPersistentStoreCoordinator: 0x300a3e610>: Attempting recovery from error encountered during addPersistentStore: 0x302f5f510 Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={reason=Failed to create file; code = 2}
error: During recovery, parent directory path reported as missing
error: Recovery attempt while adding <NSPersistentStoreDescription: 0x302f5f510> (type: SQLite, url: file:///private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application%20Support/default.store) was successful!

CoreData: error: Failed to stat path '/private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application Support/default.store', errno 2 / No such file or directory. ...
error: Recovery attempt while adding <NSPersistentStoreDescription: 0x302f5f510> (type: SQLite, url: file:///private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application%20Support/default.store) was successful!

This error message seems to indicate that the path of the data store doesn't exist, which isn't a real problem here because, when SwiftData loads a store and the store doesn't exist at the URL, SwiftData automatically creates an empty one for you. The "Recovery attempt...was successful" message in your log seems to confirm that.

Does the error have any negative impact on your app? If not, you can probably just ignore it.

Alternatively, you can make sure that the directory of the store exists before creating your model container, which I believe should eliminate the error. The root directory of your app group container can be retrieved using containerURL(forSecurityApplicationGroupIdentifier:).

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

SwiftData saying CoreData: error: Failed to stat path
 
 
Q