Skip to content

Commit b6612a4

Browse files
committed
Swallow consistency error when decoding
1 parent e3b8b40 commit b6612a4

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

Parse/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl
264264
NSArray *objectValues = offlineObjects.allValues;
265265
return [[BFTask taskForCompletionOfAllTasks:objectValues] continueWithSuccessBlock:^id(BFTask *task) {
266266
PFDecoder *decoder = [PFOfflineDecoder decoderWithOfflineObjects:offlineObjects];
267-
[object mergeFromRESTDictionary:parsedJson withDecoder:decoder];
267+
NSError *error;
268+
if (![object mergeFromRESTDictionary:parsedJson withDecoder:decoder error:&error] && error) {
269+
return [BFTask taskWithError:error];
270+
}
268271
return nil;
269272
}];
270273
}] continueWithBlock:^id(BFTask *task) {

Parse/Parse/Internal/Object/PFObjectPrivate.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@
253253
deletingEventuallyCount:(NSUInteger)deletingEventuallyCount
254254
error:(NSError **)error;
255255

256-
- (void)mergeFromRESTDictionary:(NSDictionary *)object
257-
withDecoder:(PFDecoder *)decoder;
256+
- (BOOL)mergeFromRESTDictionary:(NSDictionary *)object
257+
withDecoder:(PFDecoder *)decoder
258+
error:(NSError **)error;
258259

259260
///--------------------------------------
260261
#pragma mark - Data helpers

Parse/Parse/PFObject.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ - (NSDictionary *)RESTDictionaryWithObjectEncoder:(PFEncoder *)objectEncoder
927927
return result;
928928
}
929929

930-
- (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)decoder {
930+
- (BOOL)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)decoder error:(NSError **)error {
931931
@synchronized (lock) {
932932
BOOL mergeServerData = NO;
933933

@@ -942,6 +942,8 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
942942
} else if (!state.updatedAt) {
943943
mergeServerData = YES;
944944
}
945+
__block BOOL hasFailed = NO;
946+
__block NSError* remoteOpSetError = nil;
945947
[object enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
946948
if ([key isEqualToString:PFObjectOperationsRESTKey]) {
947949
PFOperationSet *remoteOperationSet = nil;
@@ -985,7 +987,13 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
985987
[localOperationSet.updatedAt compare:remoteOperationSet.updatedAt] != NSOrderedAscending) {
986988
[localOperationSet mergeOperationSet:remoteOperationSet];
987989
} else {
988-
PFConsistencyAssert(remoteOperationSet, @"'remoteOperationSet' should not be nil.");
990+
if (!remoteOperationSet) {
991+
NSString *message = [NSString stringWithFormat:@"'remoteOperationSet' should not be nil in object of class %@", self.parseClassName];
992+
remoteOpSetError = [PFErrorUtilities errorWithCode:-1 message:message];
993+
hasFailed = YES;
994+
*stop = YES;
995+
return;
996+
}
989997
NSUInteger index = [operationSetQueue indexOfObject:localOperationSet];
990998
[remoteOperationSet mergeOperationSet:localOperationSet];
991999
operationSetQueue[index] = remoteOperationSet;
@@ -1037,6 +1045,10 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
10371045
id decodedObject = [decoder decodeObject:obj];
10381046
[state setServerDataObject:decodedObject forKey:key];
10391047
}];
1048+
if (hasFailed && error) {
1049+
*error = remoteOpSetError;
1050+
return NO;
1051+
}
10401052
if (state.updatedAt == nil && state.createdAt != nil) {
10411053
state.updatedAt = state.createdAt;
10421054
}
@@ -1053,6 +1065,7 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
10531065
}
10541066
}
10551067
[self rebuildEstimatedData];
1068+
return YES;
10561069
}
10571070
}
10581071

Parse/Parse/PFUser.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ - (PFRESTCommand *)_constructSaveCommandForChanges:(PFOperationSet *)changes
631631
#pragma mark - REST operations
632632
///--------------------------------------
633633

634-
- (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)decoder {
634+
- (BOOL)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)decoder error:(NSError **)error {
635635
@synchronized([self lock]) {
636636
NSMutableDictionary *restDictionary = [object mutableCopy];
637637

@@ -656,7 +656,7 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
656656

657657
self._state = state;
658658

659-
[super mergeFromRESTDictionary:restDictionary withDecoder:decoder];
659+
return [super mergeFromRESTDictionary:restDictionary withDecoder:decoder error:error];
660660
}
661661
}
662662

0 commit comments

Comments
 (0)