You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have difficult bug, for one of my open-source side projects Time-Agent, that I've been trying to fix on and off for the last half a year or so.
The app somtimes crashes when I sync CoreData with a json file using this library.
The biggest mystery is that it only happends when a debugger isn't attached, so I can only debug it through the mac Console application. (Could it possibly be a race condition problem?)
To crash the app, I have to:
Open the app from outside of XCode without a debugger attached (it can be a debug build though)
Edit an item in CoreData
Press the sync button, which calls the load() function described below.
If I restart the app before pressing the sync button, it doesn't crash and no data is lost.
This could very well be a programming error on my side, but I am opening this issue because the crash report states that it is this library that causes the crash: Sync/Source/Sync/NSManagedObject+Sync.swift, line 60.
From the crash logs, it looks like all date columns are nil, that is createdAt and updatedAt, and that it crashes because these fields are required.
I don't understand why these values would be nil, they are not nil in the .json file, because they are logged after Projects to sync with the proper dates. And I would imagine that CoreData wouldn't let me save invalid entities in the first place.
So I'm left to believe that it could have something to do with the internals of this library?
Any help is much appreciated 😊
Function that causes the crash:
func load(){NSLog("Loading from sync file...")
guard let data =try?Data(contentsOf:self.path)else{NSLog("Warn: Sync file does not exist, nothing to load, saving instead...")self.save()return}
guard let json =try?JSONSerialization.jsonObject(with: data, options:[])as?[String:Any]else{NSLog("ERROR: Could not parse content of sync file")return}
guard let projects =json["projects"]as?[[String:Any]]else{NSLog("ERROR: Could not get projects from synced file")return}NSLog("Projects to sync: \(projects)")letrootGroupsPredicate=NSPredicate(format:"parent == nil", argumentArray:[])Model.context.sync(projects, inEntityNamed:"Project", predicate: rootProjectsPredicate, parent:nil){(error)in
if let error = error {print("Root projects sync error: \(error)")return}}}
Console output of the load() function above:
default 18:39:24.727413+0200 Time Agent Loading from sync file...
default 18:39:24.729429+0200 Time Agent Projects to sync: [["tasks": <__NSArrayI 0x600001b63000>(
{
archived = 0;
"created_at" = "2020-08-17T18:11:04+02:00";
duration = "62.39944994449615";
id = "812B95E0-2D25-43E0-A641-A59DB923E4AD";
name = asdf;
start = "2020-08-17T18:11:02+02:00";
"updated_at" = "2020-08-17T18:11:07+02:00";
},
<...>
default 18:39:24.739981+0200 Time Agent Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=1560 "Multiple validation errors occurred." UserInfo={NSDetailedErrors=(
"Error Domain=NSCocoaErrorDomain Code=1570 \"createdAt is a required value.\" UserInfo={NSValidationErrorObject=<Project: 0x600002dfa580> (entity: Project; id: 0xb68cee5ee76512df <x-coredata://1FC30782-FCC1-427F-AAB0-090789C8D9FC/Project/p705>; data: {\n createdAt = nil;\n group = nil;\n id = \"FD229F24-3078-4127-8359-FBAB9BED01AD\";\n name = \"Test project 123\";\n tasks = (\n \"0xb68cee5ee66512ff <x-coredata://1FC30782-FCC1-427F-AAB0-090789C8D9FC/Task/p709>\",\n \"0xb68cee5ee6e512ff <x-coredata://1FC30782-FCC1-427F-AAB0-090789C8D9FC/Task/p711>\",\n \"0xb68cee5ee62512ff <x-coredata://1FC30782-FCC1-427F-AAB0-090789C8D9FC/Task/p708>\",\n \"0xb68cee5ee6a512ff <x-coredata://1FC30782-FCC1-427F-AAB0-090789C8D9FC/Task/p710>\",\n \"0xb68cee5ee7a512ff <x-coredata://1FC30782-FCC1-427F<…>
Hi @viktorstrate, sorry for not following up earlier. I tried building your app and wasn't able to do so.
From the logs I believe some of the JSON is sending an empty createdAt date or a createdAt format that it's not parsable and it's crashing because it has been marked as a required attribute.
If you mark it as optional or make sure a proper date is always provided then it should be better
I have difficult bug, for one of my open-source side projects Time-Agent, that I've been trying to fix on and off for the last half a year or so.
The app somtimes crashes when I sync CoreData with a json file using this library.
The biggest mystery is that it only happends when a debugger isn't attached, so I can only debug it through the mac Console application. (Could it possibly be a race condition problem?)
To crash the app, I have to:
If I restart the app before pressing the sync button, it doesn't crash and no data is lost.
This could very well be a programming error on my side, but I am opening this issue because the crash report states that it is this library that causes the crash:
Sync/Source/Sync/NSManagedObject+Sync.swift, line 60
.From the crash logs, it looks like all date columns are
nil
, that iscreatedAt
andupdatedAt
, and that it crashes because these fields are required.I don't understand why these values would be
nil
, they are not nil in the .json file, because they are logged afterProjects to sync
with the proper dates. And I would imagine that CoreData wouldn't let me save invalid entities in the first place.So I'm left to believe that it could have something to do with the internals of this library?
Any help is much appreciated 😊
Function that causes the crash:
Console output of the
load()
function above:Detailed crash report:
Edit:
It's also tested with the newest version of Sync v6.0.3, with the exact same output
The text was updated successfully, but these errors were encountered: