Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added additional error checking and exception handling to the method …

…that applies sync changes. Exceptions were arising for 'could not fulfill fault'. Now they are caught, and checks done for a nil MOC.
  • Loading branch information...
commit cc038e72a1b16fd172a0db33c1bfdddbc89c8a18 1 parent 5e7a7d1
Drew McCormack authored
1  TICoreDataSync/01 Headers and Constants/TICDSTypesAndEnums.h
View
@@ -155,6 +155,7 @@ typedef enum _TICDSSyncWarningType {
TICDSSyncWarningTypeObjectWithRelationshipsChangedLocallyAlreadyDeletedByRemoteSyncChange = 5,
TICDSSyncWarningTypeObjectWithAttributesChangedRemotelyNowDeletedByLocalSyncChange = 6,
TICDSSyncWarningTypeObjectWithRelationshipsChangedRemotelyNowDeletedByLocalSyncChange = 7,
+ TICDSSyncWarningTypeObjectExceptionAroseWhileApplyingAttributeSyncChange = 8,
} TICDSSyncWarningType;
42 TICoreDataSync/02 Primary Classes/Generic Operations/TICDSSynchronizationOperation.m
View
@@ -810,25 +810,31 @@ - (void)applyObjectInsertedSyncChange:(TICDSSyncChange *)aSyncChange
- (void)applyAttributeChangeSyncChange:(TICDSSyncChange *)aSyncChange
{
- TICDSLog(TICDSLogVerbosityEveryStep, @"Applying Attribute Change sync change");
-
- TICDSSynchronizedManagedObject *object = (id)[self backgroundApplicationContextObjectForEntityName:[aSyncChange objectEntityName] syncIdentifier:[aSyncChange objectSyncID]];
-
- if( !object ) {
- TICDSLog(TICDSLogVerbosityErrorsOnly, @"Object not found locally for attribute change [%@] %@", aSyncChange, [aSyncChange objectEntityName]);
- [[self synchronizationWarnings] addObject:[TICDSUtilities syncWarningOfType:TICDSSyncWarningTypeObjectNotFoundLocallyForRemoteAttributeSyncChange entityName:[aSyncChange objectEntityName] relatedObjectEntityName:nil attributes:[aSyncChange changedAttributes]]];
- return;
+ @try {
+ TICDSLog(TICDSLogVerbosityEveryStep, @"Applying Attribute Change sync change");
+
+ TICDSSynchronizedManagedObject *object = (id)[self backgroundApplicationContextObjectForEntityName:[aSyncChange objectEntityName] syncIdentifier:[aSyncChange objectSyncID]];
+
+ if( !object || object.managedObjectContext == nil || object.isDeleted ) {
+ TICDSLog(TICDSLogVerbosityErrorsOnly, @"Object not found locally for attribute change [%@] %@", aSyncChange, [aSyncChange objectEntityName]);
+ [[self synchronizationWarnings] addObject:[TICDSUtilities syncWarningOfType:TICDSSyncWarningTypeObjectNotFoundLocallyForRemoteAttributeSyncChange entityName:[aSyncChange objectEntityName] relatedObjectEntityName:nil attributes:[aSyncChange changedAttributes]]];
+ return;
+ }
+
+ TICDSLog(TICDSLogVerbosityManagedObjectOutput, @"[%@] %@", aSyncChange, [aSyncChange objectEntityName]);
+
+ [object willChangeValueForKey:[aSyncChange relevantKey]];
+ id transformedValue = [aSyncChange changedAttributes];
+ transformedValue = [object reverseTransformedValueOfAttribute:[aSyncChange relevantKey] withValue:transformedValue];
+ [object setPrimitiveValue:transformedValue forKey:[aSyncChange relevantKey]];
+ [object didChangeValueForKey:[aSyncChange relevantKey]];
+
+ TICDSLog(TICDSLogVerbosityManagedObjectOutput, @"Changed attribute on object: %@", object);
+ }
+ @catch ( NSException *exception ) {
+ TICDSLog(TICDSLogVerbosityErrorsOnly, @"Exception thrown while applying attribute change [%@] %@: %@", aSyncChange, [aSyncChange objectEntityName], exception);
+ [[self synchronizationWarnings] addObject:[TICDSUtilities syncWarningOfType:TICDSSyncWarningTypeObjectExceptionAroseWhileApplyingAttributeSyncChange entityName:[aSyncChange objectEntityName] relatedObjectEntityName:nil attributes:[aSyncChange changedAttributes]]];
}
-
- TICDSLog(TICDSLogVerbosityManagedObjectOutput, @"[%@] %@", aSyncChange, [aSyncChange objectEntityName]);
-
- [object willChangeValueForKey:[aSyncChange relevantKey]];
- id transformedValue = [aSyncChange changedAttributes];
- transformedValue = [object reverseTransformedValueOfAttribute:[aSyncChange relevantKey] withValue:transformedValue];
- [object setPrimitiveValue:transformedValue forKey:[aSyncChange relevantKey]];
- [object didChangeValueForKey:[aSyncChange relevantKey]];
-
- TICDSLog(TICDSLogVerbosityManagedObjectOutput, @"Changed attribute on object: %@", object);
}
- (void)applyToOneRelationshipSyncChange:(TICDSSyncChange *)aSyncChange
Please sign in to comment.
Something went wrong with that request. Please try again.