Unhandled exception finding default Directory URL '+[NSPersistentContainer defaultDirectoryURL] Could not conjure up a useful location for writing persistent stores.'

https://github.com/ordo-one/package-benchmark/issues/264

Hi! I am seeing this error specifically when I try to run the Ordo One benchmarks package with a SwiftData context. I am not sure if there is something missing in Ordo One or if this is some kind of legit SwiftData error. My benchmarks seem to be running fine even after the error prints.

Any idea where that error might be coming from (and why I am not seeing that error when running SwiftData from other package executables)?

CoreData: error:  Failed to create directory file:///Users/rick/Library/Application%20Support/Benchmarks: NSCocoaErrorDomain (513)
CoreData: fault: Unhandled exception finding default Directory URL '+[NSPersistentContainer defaultDirectoryURL] Could not conjure up a useful location for writing persistent stores.'

https://github.com/vanvoorden/2024-08-26

I am running into these errors when attempting to run a benchmark on a SwiftData context from the 2024-08-26 repo. The errors seem to be harmless… the benchmark continues without crashing on those unhandled exceptions.

https://github.com/vanvoorden/2024-08-02/

I seem to have no problem running against SwiftData from a different Swift Package Executable (2024-08-02). This package seems to build and run with no errors. This package also creates the expected directory under ~/Library/Application%20Support/2024-08-02.

I don't yet completely understand what is happening… but there seems to be some reason why Benchmarks is failing to create that extra directory under Application%20Support.

I can also run Benchmarks with no errors after I add the Application%20Support/Benchmarks directory manually from mac Finder.

The benchmarks seem to be running correctly even after printing those errors… so I am not sure if there is anything important to fix in the Benchmarks package for now.

import Benchmark
import CoreData

let benchmarks = {
  Benchmark("Benchmark") { benchmark in
    let _ = NSPersistentContainer.defaultDirectoryURL
  }
}

This crashes:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSPersistentContainer defaultDirectoryURL] Could not conjure up a useful location for writing persistent stores.'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000189caa2ec __exceptionPreprocess + 176
	1   libobjc.A.dylib                     0x000000018978e158 objc_exception_throw + 60
	2   CoreData                            0x00000001904d9034 __44+[NSPersistentContainer defaultDirectoryURL]_block_invoke + 0
	3   CoreData                            0x00000001905c3f74 $sSo21NSPersistentContainerC8CoreDataE19defaultDirectoryURL10Foundation0G0VvgZ + 40
	4   Benchmarks                          0x00000001047530e4 $s10Benchmarks10benchmarks9BenchmarkACCSgycvpfiAEycfU_yADcfU_ + 92
	5   Benchmarks                          0x0000000104703608 $s9Benchmark0A8ExecutorV3runySayAA0A6ResultVGA2ACF + 2640
	6   Benchmarks                          0x0000000104728f34 $s9Benchmark0A6RunnerV3runyyYaKFTY0_ + 6768
	7   Benchmarks                          0x0000000104725cb5 $s9Benchmark0A11RunnerHooksPAAE4mainyyYaFZTQ1_ + 1
	8   Benchmarks                          0x00000001047535a5 $sIetH_yts5Error_pIegHrzo_TR10async_MainTf3npf_nTQ0_ + 1
	9   libswift_Concurrency.dylib          0x00000002513d6149 _ZL22completeTaskAndReleasePN5swift12AsyncContextEPNS_10SwiftErrorE + 1
)
libc++abi: terminating due to uncaught exception of type NSException

https://github.com/swiftlang/swift-package-manager/issues/6948

This might be another version of this error from SPM plug ins.

Building the SPM plug in with disable-sandbox seems to work around the errors… but I'm still not clear why a model context specified as an in-memory context needs a valid URL on the system to begin work.

Unhandled exception finding default Directory URL '+[NSPersistentContainer defaultDirectoryURL] Could not conjure up a useful location for writing persistent stores.'
 
 
Q