Originally created by @damianstrain on GitHub (Dec 8, 2019).
Hi John,
I am deleting an Entity by a specified key using the following code (CoreStore v6.3.2):
CoreStore.perform(
asynchronous: {(transaction) -> Int in
return try transaction.deleteAll(From<Project>(), Where<Project>(key, isEqualTo: value))
},
success: {(count) -> Void in
print("Num deleted", count)
},
failure: {(error) -> Void in
print("Error", error)
}
)
An uncaught exception gets raised when an unknown Entity key is passed, specifically in NSManagedObjectContext+Querying.swift, line 568.
I would have expected a CoreStoreError to be thrown? so that I may handle it in my failure closure. Unfortunately all I get is a SIGABRT and it crashes.
On a side note, I only came across this due to me mistyping the key😃
Originally created by @damianstrain on GitHub (Dec 8, 2019).
Hi John,
I am deleting an Entity by a specified `key` using the following code (CoreStore v6.3.2):
```
CoreStore.perform(
asynchronous: {(transaction) -> Int in
return try transaction.deleteAll(From<Project>(), Where<Project>(key, isEqualTo: value))
},
success: {(count) -> Void in
print("Num deleted", count)
},
failure: {(error) -> Void in
print("Error", error)
}
)
```
An uncaught exception gets raised when an unknown Entity `key` is passed, specifically in `NSManagedObjectContext+Querying.swift`, line 568.
<img width="983" alt="Screenshot 2019-12-07 at 23 33 26" src="https://user-images.githubusercontent.com/1780727/70381890-1c391a00-194a-11ea-9695-036463b52854.png">
I would have expected a `CoreStoreError` to be thrown? so that I may handle it in my `failure` closure. Unfortunately all I get is a `SIGABRT` and it crashes.
On a side note, I only came across this due to me mistyping the `key` 😃
@JohnEstropia commented on GitHub (Dec 11, 2019):
@damianstrain What is `key`? The recommended syntax for this is using KeyPaths as those are type-safe:
```swift
try transaction.deleteAll(
From<Project>().where(\.key ==value)
)
```
@JohnEstropia key in this case is uuid, and yes you are 100% correct, doing where(\.key ==value) is more type safe and I have since changed it to use KeyPaths.
But Im still curious though, shouldn't a CoreStoreError get thrown if the KeyPath is incorrect?
@damianstrain commented on GitHub (Dec 11, 2019):
@JohnEstropia `key` in this case is `uuid`, and yes you are 100% correct, doing `where(\.key ==value)` is more type safe and I have since changed it to use KeyPaths.
But Im still curious though, shouldn't a `CoreStoreError` get thrown if the KeyPath is incorrect?
The CoreStoreErrors are meant to be used for tracking misconfigurations in the stores or in the models. KeyPath mistakes are meant to be caught during compile time, and the type-safe syntax should be reliable enough to catch those. The type-erased dynamic utilities (like Where(_:isEqualTo:)) are meant for more complex uses, but leaves correctness as the caller's responsibility.
@JohnEstropia commented on GitHub (Jan 7, 2020):
The `CoreStoreError`s are meant to be used for tracking misconfigurations in the stores or in the models. KeyPath mistakes are meant to be caught during compile time, and the type-safe syntax should be reliable enough to catch those. The type-erased dynamic utilities (like `Where(_:isEqualTo:)`) are meant for more complex uses, but leaves correctness as the caller's responsibility.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @damianstrain on GitHub (Dec 8, 2019).
Hi John,
I am deleting an Entity by a specified
keyusing the following code (CoreStore v6.3.2):An uncaught exception gets raised when an unknown Entity
keyis passed, specifically inNSManagedObjectContext+Querying.swift, line 568.I would have expected a
CoreStoreErrorto be thrown? so that I may handle it in myfailureclosure. Unfortunately all I get is aSIGABRTand it crashes.On a side note, I only came across this due to me mistyping the
key😃@JohnEstropia commented on GitHub (Dec 11, 2019):
@damianstrain What is
key? The recommended syntax for this is using KeyPaths as those are type-safe:@damianstrain commented on GitHub (Dec 11, 2019):
@JohnEstropia
keyin this case isuuid, and yes you are 100% correct, doingwhere(\.key ==value)is more type safe and I have since changed it to use KeyPaths.But Im still curious though, shouldn't a
CoreStoreErrorget thrown if the KeyPath is incorrect?@JohnEstropia commented on GitHub (Jan 7, 2020):
The
CoreStoreErrors are meant to be used for tracking misconfigurations in the stores or in the models. KeyPath mistakes are meant to be caught during compile time, and the type-safe syntax should be reliable enough to catch those. The type-erased dynamic utilities (likeWhere(_:isEqualTo:)) are meant for more complex uses, but leaves correctness as the caller's responsibility.