Skip navigation.
 
ml-[NSManagedObjectContext save:] fails but gives no NSError
FROM : Jerry Krinock
DATE : Thu Nov 22 04:34:38 2007

The following code snippet -saves an NSManagedObjectContext and logs 
debugging info:

NSLog(@"11499 moc %x has %d insertedObjects",
    [self managedObjectContext],
    [[[self managedObjectContext] insertedObjects] count]) ;
NSLog(@"11876 Before saving, &error = %x", &error) ;
BOOL savedOK = [[self managedObjectContext] save:&error] ;
NSLog(@"11935 savedOK = %d", savedOK) ;
NSLog(@"12500 NSError saving = %@", error) ;

Gives me this:

11499 moc 15a630e0 has 1281 insertedObjects
11876 Before saving, &error = bfffef9c
11935 savedOK = 0
12500 NSError saving = (null)

Examining the store's xml file shows that indeed the save operation 
failed.  Its file modification time is 24 hours ago.  But, darn, the 
moc didn't set any NSError.

The problem is apparently some corruption in that xml file, because if 
I delete that file and re-run, everything works fine.  However, other 
than a few force-quits, I have not done anything in the last 24 hours 
which should have corrupted the file.  I have not made any changes to 
the data model or schema.

I can't see anything wrong in the apparently-corrupt file.  Comparing 
it file with the newly-created one that works, the <metadata> is the 
same and the <databaseInfo> is the same except for different <UUID> 
and <nextObjectID>, but these differences seem to be expected.

Anyone know what the unreported error might be?  I now believe that 
this also happened about a week ago, and I'm worried that some user 
operation might corrupt the file as I apparently did.

Jerry Krinock

Related mailsAuthorDate
ml-[NSManagedObjectContext save:] fails but gives no NSError Jerry Krinock Nov 22, 04:34
mlRe: -[NSManagedObjectContext save:] fails but gives no NSError Jerry Krinock Nov 23, 18:24
mlRe: -[NSManagedObjectContext save:] fails but gives no NSError mmalc crawford Nov 23, 23:46
mlRe: -[NSManagedObjectContext save:] fails but gives no NSError Jerry Krinock Nov 24, 06:47
mlRe: -[NSManagedObjectContext save:] fails but gives no NSError Chris Hanson Nov 24, 07:38
mlRe: -[NSManagedObjectContext save:] fails but gives no NSError Jerry Krinock Dec 5, 02:22