Core Data : Rare, unreproducible SQLite Constraint Error 19
Core Data : Rare, unreproducible SQLite Constraint Error 19
- Subject: Core Data : Rare, unreproducible SQLite Constraint Error 19
- From: Jerry Krinock <email@hidden>
- Date: Wed, 18 Apr 2012 20:14:34 -0700
Once every few months, my Core Data Mac app will indicate that it can't Save or Auto Save due to an error.
MyApp: Core Data: annotation: -executeRequest: encountered exception = error during SQL execution : constraint failed with userInfo = {
NSFilePath = "</path/to/document/filename.extension>";
NSSQLiteErrorDomain = 19;
}
Indeed, in the SQLite API, SQLITE_CONSTRAINT is defined to 19. So, this is some kind of low-level error.
This happened just now, after an undo operation which restored about 1500 objects that had previously been deleted. I was able to look at the call stack [1]. -[NSSQLiteConnection insertRow:] appears to be an object which contains the properties of an undo-restored leaf node in the document's data tree. The attributes look OK, its one relationship is the Z_PK (primary key) of its parent, and this parent exists with that Z_PK in the sqlite/document file. Everything looks fine as far as I can see. I wonder if it might be trying to insert a new row with the same Z_PK as an existing row, but I didn't think to check that.
The error is wrapped in another error which indicates that the "document could not be saved", and this also happens if user tries to save manually. Actually, the user cannot even close the document when it gets into this state, because the same error appears with choices of "Cancel", "Discard", and "Save". The most promising choice, "Discard", results in Auto Save trying to save again and the same error again. The only way to close the document is to force quit the app :(
This app does have an extensive data model. However I learned early on that making properties non-optional or setting constraints on values in a Core Data model is problematic, so it doesn't have any of those. In other words, it's not one of my constraints which is failing. This particular entity does have a Cascade Delete Rule from parent to child, although as I said the parent appears to be in place.
I realize that there is little likelihood that any of you will have an explanation for this, but I thought I'd throw it out there in case anyone has a clue. Archive readers, feel free to reply in the future.
I don't think it has anything to do with Auto Save. I'd bet the trouble was in the Undo. But it's not reproducible.
Jerry Krinock
[1] The Call Stack
#0 0x965a70c0 in objc_exception_throw
#1 0x95df714e in _execute
#2 0x95df6b64 in -[NSSQLiteConnection execute]
#3 0x95e48c65 in -[NSSQLiteConnection insertRow:]
#4 0x95e36cf4 in -[NSSQLConnection performAdapterOperation:]
#5 0x95e36c44 in -[NSSQLConnection performAdapterOperations:]
#6 0x95e36791 in -[NSSQLCore _performChangesWithAdapterOps:]
#7 0x95e349d7 in -[NSSQLCore performChanges]
#8 0x95e30599 in -[NSSQLCore saveChanges:]
#9 0x95dff378 in -[NSSQLCore executeRequest:withContext:error:]
#10 0x95dfe2d8 in -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
#11 0x95e29c3e in -[NSManagedObjectContext save:]
#12 0x912612b3 in -[NSPersistentDocument writeToURL:ofType:forSaveOperation:originalContentsURL:error:]
#13 0x9125ff61 in -[NSPersistentDocument writeSafelyToURL:ofType:forSaveOperation:error:]
#14 0x0019f9f9 in -[MyDocument writeSafelyToURL:ofType:forSaveOperation:error:] at MyDocument.m:4631
#15 0x910f014c in __-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_8
#16 0x910ef575 in __-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_15
#17 0x910ef436 in __-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_14
#18 0x910eff1c in __-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_7
#19 0x910c91f4 in __-[NSDocument _fileCoordinator:coordinateReadingContentsAndWritingItemAtURL:byAccessor:]_block_invoke_1
#20 0x969fe43b in __-[NSFileCoordinator(NSPrivate) _coordinateReadingItemAtURL:options:writingItemAtURL:options:error:byAccessor:]_block_invoke_3
#21 0x969fee2e in -[NSFileCoordinator(NSPrivate) _invokeAccessor:orDont:thenRelinquishAccessClaimForID:]
#22 0x96a02620 in -[NSFileCoordinator(NSPrivate) _coordinateReadingItemAtURL:options:writingItemAtURL:options:error:byAccessor:]
#23 0x910e38f5 in -[NSDocument _fileCoordinator:coordinateReadingContentsAndWritingItemAtURL:byAccessor:]
#24 0x910d0012 in __-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_1
#25 0x910e7867 in -[NSDocument performAsynchronousFileAccessUsingBlock:]
#26 0x910cfc98 in -[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]
#27 0x0019f2d0 in -[MyDocument saveToURL:ofType:forSaveOperation:completionHandler:] at MyDocument.m:4377
#28 0x910d1be6 in __-[NSDocument autosaveWithImplicitCancellability:completionHandler:]_block_invoke_1
#29 0x910c8fa9 in __-[NSDocument performAsynchronousFileAccessUsingBlock:]_block_invoke_7
#30 0x910ca4ae in -[NSDocument continueFileAccessUsingBlock:]
#31 0x910ca8e4 in __-[NSDocument performAsynchronousFileAccessUsingBlock:]_block_invoke_6
#32 0x91100d74 in __-[NSDocumentController(NSInternal) _onMainThreadInvokeWorker:]_block_invoke_3
#33 0x900d2e11 in _dispatch_call_block_and_release
#34 0x900d4da1 in _dispatch_main_queue_callback_4CF
#35 0x92338fe3 in __CFRunLoopRun
#36 0x9233847c in CFRunLoopRunSpecific
#37 0x92338328 in CFRunLoopRunInMode
#38 0x904c317f in RunCurrentEventLoopInMode
#39 0x904ca4e7 in ReceiveNextEventCommon
#40 0x904ca356 in BlockUntilNextEventMatchingListInMode
#41 0x90cfca9c in _DPSNextEvent
#42 0x90cfc306 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#43 0x90cf8675 in -[NSApplication run]
#44 0x90f8c261 in NSApplicationMain
#45 0x00001e15 in main at MainApp-Main.m:49
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden