Value.Required<URL> in CoreStoreObjects crash on empty default value #140

Closed
opened 2025-12-29 18:23:29 +01:00 by adam · 4 comments
Owner

Originally created by @ThibaultVlacich on GitHub (May 28, 2017).

I'm trying the new "no .xcdatamodeld" functionality of CoreStore 4, and I have a crash when declaring a Value of type URL

Here is the interesting part of my model:

import CoreStore

class Article: CoreStoreObject {
    
    [...]

    let url = Value.Required<URL>("url")

}

And here's the full crash stack trace, it crashes on ImportableAttributeType.swift, line 568:

Current stack trace:
0    libswiftCore.dylib                 0x0000000100b73130 swift_reportError + 129
1    libswiftCore.dylib                 0x0000000100b8fb50 _swift_stdlib_reportFatalError + 60
2    libswiftCore.dylib                 0x0000000100980250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
3    libswiftCore.dylib                 0x0000000100afae90 partial apply for (_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #2) + 109
4    libswiftCore.dylib                 0x0000000100980250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
5    libswiftCore.dylib                 0x0000000100aad9a0 specialized _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never + 96
6    CoreStore                          0x00000001004880f0 globalinit_33_B47C6585363E8666B02B41C7144D52DB_func1 + 118
7    libdispatch.dylib                  0x0000000101257784 _dispatch_client_callout + 8
8    libdispatch.dylib                  0x000000010125765c dispatch_once_f + 272
9    CoreStore                          0x0000000100487090 static URL.(cs_emptyValue() -> URL).(Static #1).empty.unsafeMutableAddressor + 40
10   CoreStore                          0x0000000100487060 static URL.cs_emptyValue() -> URL + 13
11   CoreStore                          0x0000000100487190 protocol witness for static ImportableAttributeType.cs_emptyValue() -> A in conformance URL + 24
12   CoreStore                          0x000000010051c420 ValueContainer.Required.(init(String, default : A1, isIndexed : Bool, isTransient : Bool, versionHashModifier : String?, renamingIdentifier : String?, customGetter : (A, () -> A1) -> A1, customSetter : (A, (A1) -> (), A1) -> ()) -> ValueContainer<A>.Required<A1>).(default argument 1) + 38
13   FNZKit                             0x00000001008725d0 Article.init(asMeta : ()) -> Article + 2148
14   FNZKit                             0x0000000100872590 Article.__allocating_init(asMeta : ()) -> Article + 47
15   CoreStore                          0x0000000100465010 static DynamicObject<A where ...>.meta.getter + 22
16   CoreStore                          0x00000001003c6cd0 static CoreStoreSchema.(firstPassCreateEntityDescription(from : DynamicEntity) -> NSEntityDescription).(createProperties #1)(for : CoreStoreObject.Type) -> [NSPropertyDescription] + 99
17   CoreStore                          0x00000001003c3c60 static CoreStoreSchema.firstPassCreateEntityDescription(from : DynamicEntity) -> NSEntityDescription + 703
18   CoreStore                          0x00000001003c6c20 CoreStoreSchema.(entityDescription(for : DynamicEntity, initializer : (DynamicEntity) -> NSEntityDescription) -> NSEntityDescription).(closure #1) + 66
19   CoreStore                          0x00000001003c3a50 CoreStoreSchema.entityDescription(for : DynamicEntity, initializer : (DynamicEntity) -> NSEntityDescription) -> NSEntityDescription + 251
20   CoreStore                          0x00000001003c2a00 CoreStoreSchema.rawModel() -> NSManagedObjectModel + 387
21   CoreStore                          0x00000001003c0f10 CoreStoreSchema.init(modelVersion : String, entityConfigurations : [DynamicEntity : Set<String>], versionLock : VersionLock?) -> CoreStoreSchema + 3068
22   CoreStore                          0x00000001003c0970 CoreStoreSchema.init(modelVersion : String, entities : [DynamicEntity], versionLock : VersionLock?) -> CoreStoreSchema + 602
23   CoreStore                          0x00000001003c0e20 CoreStoreSchema.__allocating_init(modelVersion : String, entities : [DynamicEntity], versionLock : VersionLock?) -> CoreStoreSchema + 109
24   FNZKit                             0x0000000100881310 static DataStore.setup() -> () + 491
25   Freenews                           0x0000000100005050 AppDelegate.applicationDidFinishLaunching(Notification) -> () + 40
26   Freenews                           0x0000000100005bb0 @objc AppDelegate.applicationDidFinishLaunching(Notification) -> () + 71
27   CoreFoundation                     0x00007fffbf378540 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
28   CoreFoundation                     0x00007fffbf3782a0 _CFXRegistrationPost + 427
29   CoreFoundation                     0x00007fffbf378180 ___CFXNotificationPost_block_invoke + 50
30   CoreFoundation                     0x00007fffbf335fa0 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
31   CoreFoundation                     0x00007fffbf3354d0 _CFXNotificationPost + 667
32   Foundation                         0x00007fffc0d778c5 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
33   AppKit                             0x00007fffbcf9d626 -[NSApplication _postDidFinishNotification] + 297
34   AppKit                             0x00007fffbcf9d3e4 -[NSApplication _sendFinishLaunchingNotification] + 208
35   AppKit                             0x00007fffbce605f1 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 552
36   AppKit                             0x00007fffbce601d6 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 661
37   Foundation                         0x00007fffc0dc2c6b -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 290
38   Foundation                         0x00007fffc0dc2ba1 _NSAppleEventManagerGenericHandler + 102
39   AE                                 0x00007fffc01c6d06 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned int, unsigned char*) + 544
40   AE                                 0x00007fffc01c6c76 dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 39
41   AE                                 0x00007fffc01c6a71 aeProcessAppleEvent + 312
42   HIToolbox                          0x00007fffbe8d3da8 AEProcessAppleEvent + 55
43   AppKit                             0x00007fffbce5b5f4 _DPSNextEvent + 1833
44   AppKit                             0x00007fffbd5d6d02 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
45   AppKit                             0x00007fffbce5003d -[NSApplication run] + 926
46   AppKit                             0x00007fffbce1a939 NSApplicationMain + 1237
47   Freenews                           0x000000010000a150 main + 13
48   libdyld.dylib                      0x00007fffd5090234 start + 1```
Originally created by @ThibaultVlacich on GitHub (May 28, 2017). I'm trying the new "_no .xcdatamodeld_" functionality of CoreStore 4, and I have a crash when declaring a `Value` of type `URL` Here is the interesting part of my model: ```swift import CoreStore class Article: CoreStoreObject { [...] let url = Value.Required<URL>("url") } ``` And here's the full crash stack trace, it crashes on `ImportableAttributeType.swift`, line 568: ```fatal error: unexpectedly found nil while unwrapping an Optional value Current stack trace: 0 libswiftCore.dylib 0x0000000100b73130 swift_reportError + 129 1 libswiftCore.dylib 0x0000000100b8fb50 _swift_stdlib_reportFatalError + 60 2 libswiftCore.dylib 0x0000000100980250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342 3 libswiftCore.dylib 0x0000000100afae90 partial apply for (_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #2) + 109 4 libswiftCore.dylib 0x0000000100980250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342 5 libswiftCore.dylib 0x0000000100aad9a0 specialized _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never + 96 6 CoreStore 0x00000001004880f0 globalinit_33_B47C6585363E8666B02B41C7144D52DB_func1 + 118 7 libdispatch.dylib 0x0000000101257784 _dispatch_client_callout + 8 8 libdispatch.dylib 0x000000010125765c dispatch_once_f + 272 9 CoreStore 0x0000000100487090 static URL.(cs_emptyValue() -> URL).(Static #1).empty.unsafeMutableAddressor + 40 10 CoreStore 0x0000000100487060 static URL.cs_emptyValue() -> URL + 13 11 CoreStore 0x0000000100487190 protocol witness for static ImportableAttributeType.cs_emptyValue() -> A in conformance URL + 24 12 CoreStore 0x000000010051c420 ValueContainer.Required.(init(String, default : A1, isIndexed : Bool, isTransient : Bool, versionHashModifier : String?, renamingIdentifier : String?, customGetter : (A, () -> A1) -> A1, customSetter : (A, (A1) -> (), A1) -> ()) -> ValueContainer<A>.Required<A1>).(default argument 1) + 38 13 FNZKit 0x00000001008725d0 Article.init(asMeta : ()) -> Article + 2148 14 FNZKit 0x0000000100872590 Article.__allocating_init(asMeta : ()) -> Article + 47 15 CoreStore 0x0000000100465010 static DynamicObject<A where ...>.meta.getter + 22 16 CoreStore 0x00000001003c6cd0 static CoreStoreSchema.(firstPassCreateEntityDescription(from : DynamicEntity) -> NSEntityDescription).(createProperties #1)(for : CoreStoreObject.Type) -> [NSPropertyDescription] + 99 17 CoreStore 0x00000001003c3c60 static CoreStoreSchema.firstPassCreateEntityDescription(from : DynamicEntity) -> NSEntityDescription + 703 18 CoreStore 0x00000001003c6c20 CoreStoreSchema.(entityDescription(for : DynamicEntity, initializer : (DynamicEntity) -> NSEntityDescription) -> NSEntityDescription).(closure #1) + 66 19 CoreStore 0x00000001003c3a50 CoreStoreSchema.entityDescription(for : DynamicEntity, initializer : (DynamicEntity) -> NSEntityDescription) -> NSEntityDescription + 251 20 CoreStore 0x00000001003c2a00 CoreStoreSchema.rawModel() -> NSManagedObjectModel + 387 21 CoreStore 0x00000001003c0f10 CoreStoreSchema.init(modelVersion : String, entityConfigurations : [DynamicEntity : Set<String>], versionLock : VersionLock?) -> CoreStoreSchema + 3068 22 CoreStore 0x00000001003c0970 CoreStoreSchema.init(modelVersion : String, entities : [DynamicEntity], versionLock : VersionLock?) -> CoreStoreSchema + 602 23 CoreStore 0x00000001003c0e20 CoreStoreSchema.__allocating_init(modelVersion : String, entities : [DynamicEntity], versionLock : VersionLock?) -> CoreStoreSchema + 109 24 FNZKit 0x0000000100881310 static DataStore.setup() -> () + 491 25 Freenews 0x0000000100005050 AppDelegate.applicationDidFinishLaunching(Notification) -> () + 40 26 Freenews 0x0000000100005bb0 @objc AppDelegate.applicationDidFinishLaunching(Notification) -> () + 71 27 CoreFoundation 0x00007fffbf378540 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 28 CoreFoundation 0x00007fffbf3782a0 _CFXRegistrationPost + 427 29 CoreFoundation 0x00007fffbf378180 ___CFXNotificationPost_block_invoke + 50 30 CoreFoundation 0x00007fffbf335fa0 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018 31 CoreFoundation 0x00007fffbf3354d0 _CFXNotificationPost + 667 32 Foundation 0x00007fffc0d778c5 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66 33 AppKit 0x00007fffbcf9d626 -[NSApplication _postDidFinishNotification] + 297 34 AppKit 0x00007fffbcf9d3e4 -[NSApplication _sendFinishLaunchingNotification] + 208 35 AppKit 0x00007fffbce605f1 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 552 36 AppKit 0x00007fffbce601d6 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 661 37 Foundation 0x00007fffc0dc2c6b -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 290 38 Foundation 0x00007fffc0dc2ba1 _NSAppleEventManagerGenericHandler + 102 39 AE 0x00007fffc01c6d06 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned int, unsigned char*) + 544 40 AE 0x00007fffc01c6c76 dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 39 41 AE 0x00007fffc01c6a71 aeProcessAppleEvent + 312 42 HIToolbox 0x00007fffbe8d3da8 AEProcessAppleEvent + 55 43 AppKit 0x00007fffbce5b5f4 _DPSNextEvent + 1833 44 AppKit 0x00007fffbd5d6d02 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796 45 AppKit 0x00007fffbce5003d -[NSApplication run] + 926 46 AppKit 0x00007fffbce1a939 NSApplicationMain + 1237 47 Freenews 0x000000010000a150 main + 13 48 libdyld.dylib 0x00007fffd5090234 start + 1```
adam added the enhancementfixed labels 2025-12-29 18:23:29 +01:00
adam closed this issue 2025-12-29 18:23:29 +01:00
Author
Owner

@JohnEstropia commented on GitHub (May 28, 2017):

@ThibaultVlacich Thanks for the report. It looks like we can't use empty string on URL, but is fine with NSURL 🤔
In the meantime I suggest the following workarounds:

  • provide a default value: let url = Value.Required<URL>("url", default: URL(string: "http://")!)
  • use Value.Optional<URL> instead
  • user Value.Required<NSURL> instead (would fail if the empty NSURL is casted to URL)

In hindsight I should separate ImportableAttributeTypes that can and cannot have "empty" values. Ill look for an elegant way for it.

@JohnEstropia commented on GitHub (May 28, 2017): @ThibaultVlacich Thanks for the report. It looks like we can't use empty string on `URL`, but is fine with `NSURL` 🤔 In the meantime I suggest the following workarounds: - provide a default value: `let url = Value.Required<URL>("url", default: URL(string: "http://")!)` - use `Value.Optional<URL>` instead - user `Value.Required<NSURL>` instead (would fail if the empty `NSURL` is casted to `URL`) In hindsight I should separate `ImportableAttributeType`s that can and cannot have "empty" values. Ill look for an elegant way for it.
Author
Owner

@JohnEstropia commented on GitHub (May 28, 2017):

@ThibaultVlacich Okay I "fixed" this in 4.0.1. Basically some types will now require the default: argument.

let flag = Value.Required<Bool>("flag") // OK. Defaults to false
let age = Value.Required<Int>("age") // OK. Defaults to 0
let name = Value.Required<String>("name") // OK. Defaults to "" (empty string)

let url = Value.Required<URL>("url") // Compiler error
let blog = Value.Required<URL>("blog", default: URL(string: "http://")!) // OK

These "non-emptyable" types include URL, NSURL, Date, NSDate, UUID, and NSUUID.

@JohnEstropia commented on GitHub (May 28, 2017): @ThibaultVlacich Okay I "fixed" this in 4.0.1. Basically some types will now require the `default:` argument. ```swift let flag = Value.Required<Bool>("flag") // OK. Defaults to false let age = Value.Required<Int>("age") // OK. Defaults to 0 let name = Value.Required<String>("name") // OK. Defaults to "" (empty string) let url = Value.Required<URL>("url") // Compiler error let blog = Value.Required<URL>("blog", default: URL(string: "http://")!) // OK ``` These "non-emptyable" types include `URL`, `NSURL`, `Date`, `NSDate`, `UUID`, and `NSUUID`.
Author
Owner

@ThibaultVlacich commented on GitHub (May 28, 2017):

Thanks. I've choose to mark my url as Optional, a bit cleaner I think :)

@ThibaultVlacich commented on GitHub (May 28, 2017): Thanks. I've choose to mark my url as Optional, a bit cleaner I think :)
Author
Owner

@JohnEstropia commented on GitHub (May 29, 2017):

Yup, I recommend that as well. But now the compiler checks it for us :)
Closing this issue, thanks again!

@JohnEstropia commented on GitHub (May 29, 2017): Yup, I recommend that as well. But now the compiler checks it for us :) Closing this issue, thanks again!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore-JohnEstropia#140