diff --git a/Parse/Internal/FieldOperation/PFFieldOperation.m b/Parse/Internal/FieldOperation/PFFieldOperation.m index 7ae075867..116c6f668 100644 --- a/Parse/Internal/FieldOperation/PFFieldOperation.m +++ b/Parse/Internal/FieldOperation/PFFieldOperation.m @@ -25,17 +25,17 @@ @implementation PFFieldOperation - (id)encodeWithObjectEncoder:(PFEncoder *)objectEncoder { - PFConsistencyAssert(NO, @"Operation is invalid."); + PFConsistencyAssertionFailure(@"Operation is invalid."); return nil; } - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous { - PFConsistencyAssert(NO, @"Operation is invalid."); + PFConsistencyAssertionFailure(@"Operation is invalid."); return nil; } - (id)applyToValue:(id)oldValue forKey:(NSString *)key { - PFConsistencyAssert(NO, @"Operation is invalid."); + PFConsistencyAssertionFailure(@"Operation is invalid."); return nil; } @@ -153,7 +153,7 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous { withNumber:((PFIncrementOperation *)previous).amount]; return [PFIncrementOperation incrementWithAmount:newAmount]; } - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } @@ -208,7 +208,7 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous { NSArray *newArray = [oldArray arrayByAddingObjectsFromArray:self.objects]; return [PFSetOperation setWithValue:newArray]; } else { - [NSException raise:NSInternalInconsistencyException format:@"You can't add an item to a non-array."]; + PFConsistencyAssertionFailure(@"Unable to add an item to a non-array."); return nil; } } else if ([previous isKindOfClass:[PFAddOperation class]]) { @@ -216,7 +216,7 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous { [newObjects addObjectsFromArray:self.objects]; return [[self class] addWithObjects:newObjects]; } - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } @@ -226,7 +226,7 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key { } else if ([oldValue isKindOfClass:[NSArray class]]) { return [((NSArray *)oldValue)arrayByAddingObjectsFromArray:self.objects]; } - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } @@ -267,14 +267,14 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous { NSArray *oldArray = (((PFSetOperation *)previous).value); return [PFSetOperation setWithValue:[self applyToValue:oldArray forKey:nil]]; } else { - [NSException raise:NSInternalInconsistencyException format:@"You can't add an item to a non-array."]; + PFConsistencyAssertionFailure(@"Unable to add an item to a non-array."); return nil; } } else if ([previous isKindOfClass:[PFAddUniqueOperation class]]) { NSArray *previousObjects = ((PFAddUniqueOperation *)previous).objects; return [[self class] addUniqueWithObjects:[self applyToValue:previousObjects forKey:nil]]; } - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } @@ -302,7 +302,7 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key { } return newValue; } - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } @@ -336,14 +336,14 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous { if (!previous) { return self; } else if ([previous isKindOfClass:[PFDeleteOperation class]]) { - [NSException raise:NSInternalInconsistencyException format:@"You can't remove items from a deleted array."]; + PFConsistencyAssertionFailure(@"Unable to remove items from a deleted array."); return nil; } else if ([previous isKindOfClass:[PFSetOperation class]]) { if ([((PFSetOperation *)previous).value isKindOfClass:[NSArray class]]) { NSArray *oldArray = ((PFSetOperation *)previous).value; return [PFSetOperation setWithValue:[self applyToValue:oldArray forKey:nil]]; } else { - [NSException raise:NSInternalInconsistencyException format:@"You can't add an item to a non-array."]; + PFConsistencyAssertionFailure(@"Unable to add an item to a non-array."); return nil; } } else if ([previous isKindOfClass:[PFRemoveOperation class]]) { @@ -351,7 +351,7 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous { return [PFRemoveOperation removeWithObjects:newObjects]; } - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } @@ -379,7 +379,7 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key { } return newValue; } - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } @@ -474,8 +474,7 @@ - (id)encodeWithObjectEncoder:(PFEncoder *)objectEncoder { if (removeDict) { return removeDict; } - - [NSException raise:NSInternalInconsistencyException format:@"A PFRelationOperation was created without any data."]; + PFConsistencyAssertionFailure(@"A PFRelationOperation was created without any data."); return nil; } @@ -535,7 +534,7 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key { } } } else { - [NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."]; + PFConsistencyAssertionFailure(@"This operation is invalid after previous operation."); return nil; } diff --git a/Parse/Internal/Installation/Controller/PFInstallationController.m b/Parse/Internal/Installation/Controller/PFInstallationController.m index c656d1279..c28907fdf 100644 --- a/Parse/Internal/Installation/Controller/PFInstallationController.m +++ b/Parse/Internal/Installation/Controller/PFInstallationController.m @@ -83,12 +83,12 @@ - (BFTask *)processFetchResultAsync:(NSDictionary *)result forObject:(PFObject * ///-------------------------------------- - (BFTask *)deleteObjectAsync:(PFObject *)object withSessionToken:(nullable NSString *)sessionToken { - PFConsistencyAssert(NO, @"Installations cannot be deleted."); + PFConsistencyAssertionFailure(@"Installations cannot be deleted."); return nil; } - (BFTask *)processDeleteResultAsync:(nullable NSDictionary *)result forObject:(PFObject *)object { - PFConsistencyAssert(NO, @"Installations cannot be deleted."); + PFConsistencyAssertionFailure(@"Installations cannot be deleted."); return nil; } diff --git a/Parse/Internal/LocalDataStore/OfflineQueryLogic/PFOfflineQueryLogic.m b/Parse/Internal/LocalDataStore/OfflineQueryLogic/PFOfflineQueryLogic.m index d1e4ce2b5..3ff4530d0 100644 --- a/Parse/Internal/LocalDataStore/OfflineQueryLogic/PFOfflineQueryLogic.m +++ b/Parse/Internal/LocalDataStore/OfflineQueryLogic/PFOfflineQueryLogic.m @@ -126,7 +126,7 @@ - (id)valueForContainer:(id)container return [self valueForContainer:restFormat key:rest depth:depth + 1]; } } - [NSException raise:NSInvalidArgumentException format:@"Key %@ is invalid", key]; + PFParameterAssertionFailure(@"Key %@ is invalid.", key); } return [self valueForContainer:value key:rest depth:depth + 1]; } @@ -152,7 +152,7 @@ - (id)valueForContainer:(id)container } else if (container == nil) { return nil; } else { - [NSException raise:NSInvalidArgumentException format:@"Bad key %@", key]; + PFParameterAssertionFailure(@"Bad key %@", key); // Shouldn't reach here. return nil; } @@ -457,9 +457,7 @@ + (BOOL)matchesValue:(id)value } else if ([operator isEqualToString:PFQueryKeyWithin]) { return [self matchesValue:value within:constraint]; } - - [NSException raise:NSInvalidArgumentException - format:@"The offline store does not yet support %@ operator.", operator]; + PFParameterAssertionFailure(@"Local Datastore does not yet support %@ operator.", operator); // Shouldn't reach here return YES; } @@ -710,10 +708,9 @@ - (BFTask *)fetchIncludeAsync:(NSString *)include // throwing an exception. return nil; } - NSException *exception = [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"include is invalid" - userInfo:nil]; - return [BFTask taskWithException:exception]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidNestedKey + message:@"include is invalid"]; + return [BFTask taskWithError:error]; }] continueWithSuccessBlock:^id(BFTask *task) { return [self fetchIncludeAsync:rest container:task.result database:database]; }]; diff --git a/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m b/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m index 044e1f4ce..2d6844007 100644 --- a/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m +++ b/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m @@ -178,8 +178,7 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl PFOfflineStoreKeyOfJSON, PFOfflineStoreTableOfObjects, PFOfflineStoreKeyOfUUID]; return [database executeQueryAsync:query withArgumentsInArray:@[ uuid ] block:^id(PFSQLiteDatabaseResult *_Nonnull result) { if (![result next]) { - [NSException raise:NSInternalInconsistencyException - format:@"Attempted to find non-existent uuid %@.", uuid]; + PFConsistencyAssertionFailure(@"Attempted to find non-existent uuid %@. Please report this issue with stack traces and logs.", uuid); } return [result stringForColumnIndex:0]; }]; @@ -189,10 +188,10 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl if (uuidTask && !(self.options & PFOfflineStoreOptionAlwaysFetchFromSQLite)) { // This object is an existing ParseObject, and we must've already pulled its data // out of the offline store, or else we wouldn't know its UUID. This should never happen. - NSString *message = @"Object must have already been fetched but isn't marked as fetched."; - [tcs setException:[NSException exceptionWithName:NSInternalInconsistencyException - reason:message - userInfo:nil]]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorObjectNotFound + message:@"Object must have already been fetched but isn't marked as fetched." + shouldLog:NO]; + [tcs setError:error]; @synchronized(self.lock) { [self.fetchedObjects removeObjectForKey:object]; @@ -215,9 +214,8 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl __block NSString *newUUID = nil; jsonStringTask = [[database executeQueryAsync:query withArgumentsInArray:@[ className, objectId ] block:^id(PFSQLiteDatabaseResult *_Nonnull result) { if (![result next]) { - NSString *errorMessage = @"This object is not available in the offline cache."; NSError *error = [PFErrorUtilities errorWithCode:kPFErrorCacheMiss - message:errorMessage + message:@"This object is not available in the offline cache." shouldLog:NO]; return [BFTask taskWithError:error]; } @@ -581,10 +579,10 @@ - (BFTask *)findAsyncForQueryState:(PFQueryState *)queryState @synchronized(self.lock) { fetchTask = [self.fetchedObjects objectForKey:object]; if (!fetchTask) { - NSException *exception = [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"An object cannot be updated if it wasn't fetched" - userInfo:nil]; - return [BFTask taskWithException:exception]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorObjectNotFound + message:@"An object cannot be updated if it wasn't fetched" + shouldLog:NO]; + return [BFTask taskWithError:error]; } } return [fetchTask continueWithBlock:^id(BFTask *task) { @@ -909,8 +907,7 @@ - (BFTask *)findAsyncForQueryState:(PFQueryState *)queryState __block NSString *objectId = nil; return [[database executeQueryAsync:query withArgumentsInArray:@[ uuid ] block:^id(PFSQLiteDatabaseResult *result) { if (![result next]) { - [NSException raise:NSInternalInconsistencyException - format:@"Attempted to find non-existent uuid %@", uuid]; // TODO: (nlutsenko) Convert to errors. + PFConsistencyAssertionFailure(@"Attempted to find non-existent uuid %@. Please report this issue with stack traces and logs.", uuid); } className = [result stringForColumnIndex:0]; diff --git a/Parse/Internal/PFAssert.h b/Parse/Internal/PFAssert.h index 6e8c59d2d..2b0cd7401 100644 --- a/Parse/Internal/PFAssert.h +++ b/Parse/Internal/PFAssert.h @@ -24,16 +24,25 @@ } \ } while(0) +/** + Raises an `NSInvalidArgumentException`. Use `description` to supply the way to fix the exception. + */ +#define PFParameterAssertionFailure(description, ...) \ +do {\ + [NSException raise:NSInvalidArgumentException \ + format:description, ##__VA_ARGS__]; \ +} while(0) + /** Raises an `NSRangeException` if the `condition` does not pass. Use `description` to supply the way to fix the exception. */ #define PFRangeAssert(condition, description, ...) \ - do {\ - if (!(condition)) { \ - [NSException raise:NSRangeException \ - format:description, ##__VA_ARGS__]; \ - } \ +do {\ + if (!(condition)) { \ + [NSException raise:NSRangeException \ + format:description, ##__VA_ARGS__]; \ +} \ } while(0) /** @@ -41,12 +50,21 @@ Use `description` to supply the way to fix the exception. */ #define PFConsistencyAssert(condition, description, ...) \ - do { \ - if (!(condition)) { \ - [NSException raise:NSInternalInconsistencyException \ - format:description, ##__VA_ARGS__]; \ - } \ - } while(0) +do { \ + if (!(condition)) { \ + [NSException raise:NSInternalInconsistencyException \ + format:description, ##__VA_ARGS__]; \ + } \ +} while(0) + +/** + Raises an `NSInternalInconsistencyException`. Use `description` to supply the way to fix the exception. + */ +#define PFConsistencyAssertionFailure(description, ...) \ +do {\ + [NSException raise:NSInternalInconsistencyException \ + format:description, ##__VA_ARGS__]; \ +} while(0) /** Always raises `NSInternalInconsistencyException` with details @@ -54,10 +72,9 @@ */ #define PFNotDesignatedInitializer() \ do { \ - PFConsistencyAssert(NO, \ - @"%@ is not the designated initializer for instances of %@.", \ - NSStringFromSelector(_cmd), \ - NSStringFromClass([self class])); \ + PFConsistencyAssertionFailure(@"%@ is not the designated initializer for instances of %@.", \ + NSStringFromSelector(_cmd), \ + NSStringFromClass([self class])); \ return nil; \ } while (0) diff --git a/Parse/Internal/PFEncoder.m b/Parse/Internal/PFEncoder.m index 3c515ee92..c44f42195 100644 --- a/Parse/Internal/PFEncoder.m +++ b/Parse/Internal/PFEncoder.m @@ -55,9 +55,6 @@ - (id)encodeObject:(id)object { // Returning this empty object is strictly wrong, but we have to have *something* // to put into an object's mutable container cache, and this is just about the // best we can do right now. - // - // [NSException raise:NSInternalInconsistencyException - // format:@"Tried to serialize an unsaved file."]; return @{ @"__type" : @"File" }; } return @{ @@ -122,7 +119,7 @@ + (instancetype)objectEncoder { } - (id)encodeParseObject:(PFObject *)object { - [NSException raise:NSInternalInconsistencyException format:@"PFObjects are not allowed here."]; + PFConsistencyAssertionFailure(@"PFObjects are not allowed here."); return nil; } diff --git a/Parse/Internal/PFEventuallyQueue.m b/Parse/Internal/PFEventuallyQueue.m index 8935944c3..9c38ad703 100644 --- a/Parse/Internal/PFEventuallyQueue.m +++ b/Parse/Internal/PFEventuallyQueue.m @@ -325,11 +325,10 @@ - (BFTask *)_runCommand:(id)command withIdentifier:(NSString * return [self.dataSource.commandRunner runCommandAsync:(PFRESTCommand *)command withOptions:0]; } - NSString *reason = [NSString stringWithFormat:@"Can't find a compatible runner for command %@.", command]; - NSException *exception = [NSException exceptionWithName:NSInternalInconsistencyException - reason:reason - userInfo:nil]; - return [BFTask taskWithException:exception]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInternalServer + message:[NSString stringWithFormat:@"Can't find a compatible runner for command %@.", command] + shouldLog:NO]; + return [BFTask taskWithError:error]; } - (BFTask *)_didFinishRunningCommand:(id)command diff --git a/Parse/Internal/PFInternalUtils.m b/Parse/Internal/PFInternalUtils.m index ed8775dfb..87f745a11 100644 --- a/Parse/Internal/PFInternalUtils.m +++ b/Parse/Internal/PFInternalUtils.m @@ -152,8 +152,7 @@ + (void)appendObject:(id)object toString:(NSMutableString *)string { } else if ([object isKindOfClass:[NSNull class]]) { [self appendNullToString:string]; } else { - [NSException raise:NSInvalidArgumentException - format:@"Couldn't create cache key from %@", object]; + PFParameterAssertionFailure(@"Couldn't create cache key from %@", object); } } diff --git a/Parse/Internal/PFPinningEventuallyQueue.m b/Parse/Internal/PFPinningEventuallyQueue.m index 990c8df10..80edaed2a 100644 --- a/Parse/Internal/PFPinningEventuallyQueue.m +++ b/Parse/Internal/PFPinningEventuallyQueue.m @@ -281,10 +281,10 @@ - (BFTask *)_waitForOperationSet:(PFOperationSet *)operationSet eventuallyPin:(P } }); if (uuid == nil) { - NSException *exception = [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"Either operationSet or eventuallyPin must be set" - userInfo:nil]; - return [BFTask taskWithException:exception]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorIncorrectType + message:@"Either operationSet or eventuallyPin must be set" + shouldLog:NO]; + return [BFTask taskWithError:error]; } return [BFTask taskWithResult:nil]; } diff --git a/Parse/Internal/PropertyInfo/PFPropertyInfo_Runtime.m b/Parse/Internal/PropertyInfo/PFPropertyInfo_Runtime.m index 358747b33..be2afaf48 100644 --- a/Parse/Internal/PropertyInfo/PFPropertyInfo_Runtime.m +++ b/Parse/Internal/PropertyInfo/PFPropertyInfo_Runtime.m @@ -12,6 +12,8 @@ #import #import +#import "PFAssert.h" + /** This macro is really interesting. Because ARC will insert implicit retains, releases and other memory managment code that we don't want here, we have to basically trick ARC into treating the functions we want as functions with type @@ -45,7 +47,7 @@ void object_getIvarValue_safe(__unsafe_unretained id obj, Ivar ivar, void *toMem switch (associationType) { case PFPropertyInfoAssociationTypeDefault: - [NSException raise:NSInvalidArgumentException format:@"Invalid association type Default!"]; + PFParameterAssertionFailure(@"Invalid association type `Default`."); break; case PFPropertyInfoAssociationTypeAssign: { @@ -86,7 +88,7 @@ void object_setIvarValue_safe(__unsafe_unretained id obj, Ivar ivar, void *fromM switch (associationType) { case PFPropertyInfoAssociationTypeDefault: - [NSException raise:NSInvalidArgumentException format:@"Invalid association type Default!"]; + PFParameterAssertionFailure(@"Invalid association type `Default`."); return; case PFPropertyInfoAssociationTypeAssign: { diff --git a/Parse/Internal/Query/Controller/PFCachedQueryController.m b/Parse/Internal/Query/Controller/PFCachedQueryController.m index d3ea38966..20dcca7b6 100644 --- a/Parse/Internal/Query/Controller/PFCachedQueryController.m +++ b/Parse/Internal/Query/Controller/PFCachedQueryController.m @@ -112,10 +112,10 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command } break; case kPFCachePolicyCacheThenNetwork: - PFConsistencyAssert(NO, @"kPFCachePolicyCacheThenNetwork is not implemented as a runner."); + PFConsistencyAssertionFailure(@"kPFCachePolicyCacheThenNetwork is not implemented as a runner."); break; default: - PFConsistencyAssert(NO, @"Unrecognized cache policy: %d", queryState.cachePolicy); + PFConsistencyAssertionFailure(@"Unrecognized cache policy: %d", queryState.cachePolicy); break; } return nil; diff --git a/Parse/Internal/Query/Utilities/PFQueryUtilities.m b/Parse/Internal/Query/Utilities/PFQueryUtilities.m index 91701ae10..522e7b9a3 100644 --- a/Parse/Internal/Query/Utilities/PFQueryUtilities.m +++ b/Parse/Internal/Query/Utilities/PFQueryUtilities.m @@ -47,7 +47,6 @@ + (NSPredicate *)_mapPredicate:(NSPredicate *)predicate return [[NSCompoundPredicate alloc] initWithType:type subpredicates:newSubpredicates]; } } - if ([predicate isKindOfClass:[NSComparisonPredicate class]]) { if (comparisonBlock) { return comparisonBlock((NSComparisonPredicate *)predicate); @@ -55,8 +54,7 @@ + (NSPredicate *)_mapPredicate:(NSPredicate *)predicate return predicate; } } - - [NSException raise:NSInternalInconsistencyException format:@"NSExpression predicates are not supported."]; + PFConsistencyAssertionFailure(@"NSExpression predicates are not supported."); return nil; } @@ -87,9 +85,8 @@ + (NSPredicate *)_negatePredicate:(NSPredicate *)predicate { return [NSCompoundPredicate andPredicateWithSubpredicates:newSubpredicates]; } default: { - [NSException raise:NSInternalInconsistencyException - format:@"This compound predicate cannot be negated. (%zd)", - compound.compoundPredicateType]; + PFConsistencyAssertionFailure(@"This compound predicate cannot be negated. (%zd)", + compound.compoundPredicateType); return nil; } } @@ -129,8 +126,7 @@ + (NSPredicate *)_negatePredicate:(NSPredicate *)predicate { break; } case NSBetweenPredicateOperatorType: { - [NSException raise:NSInternalInconsistencyException - format:@"A BETWEEN predicate was found after they should have been removed."]; + PFConsistencyAssertionFailure(@"A BETWEEN predicate was found after they should have been removed."); } case NSMatchesPredicateOperatorType: case NSLikePredicateOperatorType: @@ -139,8 +135,7 @@ + (NSPredicate *)_negatePredicate:(NSPredicate *)predicate { case NSContainsPredicateOperatorType: case NSCustomSelectorPredicateOperatorType: default: { - [NSException raise:NSInternalInconsistencyException - format:@"This comparison predicate cannot be negated. (%@)", comparison]; + PFConsistencyAssertionFailure(@"This comparison predicate cannot be negated. (%@)", comparison); return nil; } } @@ -358,8 +353,7 @@ + (NSPredicate *)asOrOfAnds:(NSCompoundPredicate *)compound { } } else { - [NSException raise:NSInternalInconsistencyException - format:@"[PFQuery asOrOfAnds:] found a compound query that wasn't OR or AND."]; + PFConsistencyAssertionFailure(@"[PFQuery asOrOfAnds:] found a compound query that wasn't OR or AND."); } } else { // Just add this condition to all the conjunctions in progress. @@ -388,10 +382,7 @@ + (NSPredicate *)asOrOfAnds:(NSCompoundPredicate *)compound { return [NSCompoundPredicate orPredicateWithSubpredicates:andPredicates]; } } - - [NSException raise:NSInternalInconsistencyException - format:@"[PFQuery asOrOfAnds:] was passed a compound query that wasn't OR or AND."]; - + PFConsistencyAssertionFailure(@"[PFQuery asOrOfAnds:] was passed a compound query that wasn't OR or AND."); return nil; } diff --git a/Parse/PFObject.m b/Parse/PFObject.m index 118837488..b4228ed91 100644 --- a/Parse/PFObject.m +++ b/Parse/PFObject.m @@ -78,7 +78,7 @@ static void PFObjectAssertValueIsKindOfValidClass(id object) { } } - PFParameterAssert(NO, @"PFObject values may not have class: %@", [object class]); + PFParameterAssertionFailure(@"PFObject values may not have class: %@", [object class]); } @interface PFObject () { @@ -252,8 +252,7 @@ + (void)collectDirtyChildren:(id)node seenNew = [NSSet set]; } else { if ([seenNew containsObject:object]) { - [NSException raise:NSInternalInconsistencyException - format:@"Found a circular dependency when saving."]; + PFConsistencyAssertionFailure(@"Found a circular dependency when saving."); } seenNew = [seenNew setByAddingObject:object]; } @@ -425,8 +424,7 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *) // We do cycle-detection when building the list of objects passed to this // function, so this should never get called. But we should check for it // anyway, so that we get an exception instead of an infinite loop. - [NSException raise:NSInternalInconsistencyException - format:@"Unable to save a PFObject with a relation to a cycle."]; + PFConsistencyAssertionFailure(@"Unable to save a PFObject with a relation to a cycle."); } // If a lazy user is one of the objects in the array, resolve its laziness now and @@ -554,18 +552,16 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *) // Just like deepSaveAsync, but uses saveEventually instead of saveAsync. // Because you shouldn't wait for saveEventually calls to complete, this // does not return any operation. -+ (BFTask *)_enqueueSaveEventuallyChildrenOfObject:(PFObject *)object - currentUser:(PFUser *)currentUser { ++ (BFTask *)_enqueueSaveEventuallyChildrenOfObject:(PFObject *)object currentUser:(PFUser *)currentUser { return [BFTask taskFromExecutor:[BFExecutor defaultExecutor] withBlock:^id{ NSMutableSet *uniqueObjects = [NSMutableSet set]; NSMutableSet *uniqueFiles = [NSMutableSet set]; [self collectDirtyChildren:object children:uniqueObjects files:uniqueFiles currentUser:currentUser]; for (PFFile *file in uniqueFiles) { if (!file.url) { - NSException *exception = [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"Unable to saveEventually a PFObject with a relation to a new, unsaved PFFile." - userInfo:nil]; - return [BFTask taskWithException:exception]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorUnsavedFile + message:@"Unable to saveEventually a PFObject with a relation to a new, unsaved PFFile."]; + return [BFTask taskWithError:error]; } } @@ -593,8 +589,7 @@ + (BFTask *)_enqueueSaveEventuallyChildrenOfObject:(PFObject *)object // We do cycle-detection when building the list of objects passed to this // function, so this should never get called. But we should check for it // anyway, so that we get an exception instead of an infinite loop. - [NSException raise:NSInternalInconsistencyException - format:@"Unable to save a PFObject with a relation to a cycle."]; + PFConsistencyAssertionFailure(@"Unable to save a PFObject with a relation to a cycle."); } // If a lazy user is one of the objects in the array, resolve its laziness now and @@ -762,8 +757,7 @@ - (void)resolveLocalId { // But if it has local ids that haven't been resolved yet, then that's not going to // be possible. if (!newObjectId) { - [NSException raise:NSInternalInconsistencyException - format:@"Tried to save an object with a pointer to a new, unsaved object."]; + PFConsistencyAssertionFailure(@"Tried to save an object with a pointer to a new, unsaved object."); } // Nil out the localId so that the new objectId won't be saved back to the PFObjectLocalIdStore. @@ -1128,11 +1122,9 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren { */ - (BFTask *)_enqueueSaveEventuallyOperationAsync:(PFOperationSet *)operationSet { if (!operationSet.isSaveEventually) { - NSString *message = @"This should only be used to enqueue saveEventually operation sets"; - NSException *exception = [NSException exceptionWithName:NSInternalInconsistencyException - reason:message - userInfo:nil]; - return [BFTask taskWithException:exception]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorOperationForbidden + message:@"Unable to enqueue non-saveEventually operation set."]; + return [BFTask taskWithError:error]; } return [self.taskQueue enqueue:^BFTask *(BFTask *toAwait) { diff --git a/Parse/PFQuery.m b/Parse/PFQuery.m index ddfd6d57f..e346d6401 100644 --- a/Parse/PFQuery.m +++ b/Parse/PFQuery.m @@ -53,7 +53,7 @@ static void PFQueryAssertValidEqualityClauseClass(id object) { } } - PFParameterAssert(NO, @"Cannot do a comparison query for type: %@", [object class]); + PFParameterAssertionFailure(@"Cannot do a comparison query for type: %@", [object class]); } /** @@ -72,7 +72,7 @@ static void PFQueryAssertValidOrderingClauseClass(id object) { } } - PFParameterAssert(NO, @"Cannot do a query that requires ordering for type: %@", [object class]); + PFParameterAssertionFailure(@"Cannot do a query that requires ordering for type: %@", [object class]); } @interface PFQuery () { @@ -467,15 +467,13 @@ - (void)whereComparisonPredicate:(NSComparisonPredicate *)predicate { // Like "value IN SELF" [self whereKeyExists:left.keyPath]; } else { - [NSException raise:NSInternalInconsistencyException - format:@"An IN predicate must have a key path and a constant."]; + PFConsistencyAssertionFailure(@"An IN predicate must have a key path and a constant."); } return; } case NSCustomSelectorPredicateOperatorType: { if (predicate.customSelector != NSSelectorFromString(@"notContainedIn:")) { - [NSException raise:NSInternalInconsistencyException - format:@"Predicates with custom selectors are not supported."]; + PFConsistencyAssertionFailure(@"Predicates with custom selectors are not supported."); } if (right.expressionType == NSConstantValueExpressionType && @@ -502,8 +500,7 @@ - (void)whereComparisonPredicate:(NSComparisonPredicate *)predicate { // Like "NOT (value IN SELF)" [self whereKeyDoesNotExist:left.keyPath]; } else { - [NSException raise:NSInternalInconsistencyException - format:@"A NOT IN predicate must have a key path and a constant array."]; + PFConsistencyAssertionFailure(@"A NOT IN predicate must have a key path and a constant array."); } return; } @@ -512,32 +509,19 @@ - (void)whereComparisonPredicate:(NSComparisonPredicate *)predicate { [self whereKey:left.keyPath hasPrefix:right.constantValue]; return; } - case NSContainsPredicateOperatorType: { - [NSException raise:NSInternalInconsistencyException - format:@"Regex queries are not supported with " - "[PFQuery queryWithClassName:predicate:]. Please try to structure your " - "data so that you can use an equalTo or containedIn query."]; - } - case NSEndsWithPredicateOperatorType: { - [NSException raise:NSInternalInconsistencyException - format:@"Regex queries are not supported with " - "[PFQuery queryWithClassName:predicate:]. Please try to structure your " - "data so that you can use an equalTo or containedIn query."]; - } + case NSContainsPredicateOperatorType: + case NSEndsWithPredicateOperatorType: case NSMatchesPredicateOperatorType: { - [NSException raise:NSInternalInconsistencyException - format:@"Regex queries are not supported with " - "[PFQuery queryWithClassName:predicate:]. Please try to structure your " - "data so that you can use an equalTo or containedIn query."]; + PFConsistencyAssertionFailure(@"Regex queries are not supported with " + "[PFQuery queryWithClassName:predicate:]. Please try to structure your " + "data so that you can use an equalTo or containedIn query."); } case NSLikePredicateOperatorType: { - [NSException raise:NSInternalInconsistencyException - format:@"LIKE is not supported by PFQuery."]; + PFConsistencyAssertionFailure(@"LIKE is not supported by PFQuery."); } case NSBetweenPredicateOperatorType: default: { - [NSException raise:NSInternalInconsistencyException - format:@"This comparison predicate is not supported. (%zd)", predicate.predicateOperatorType]; + PFConsistencyAssertionFailure(@"This comparison predicate is not supported. (%zd)", predicate.predicateOperatorType); } } } @@ -562,9 +546,7 @@ + (instancetype)queryWithClassName:(NSString *)className normalizedPredicate:(NS if ([subpredicate isKindOfClass:[NSCompoundPredicate class]] && ((NSCompoundPredicate *)subpredicate).compoundPredicateType == NSOrPredicateType) { if (query) { - [NSException raise:NSInternalInconsistencyException - format:@"A query had 2 ORs in an AND after normalization. %@", - predicate]; + PFConsistencyAssertionFailure(@"A query had 2 ORs in an AND after normalization. %@", predicate); } query = [self queryWithClassName:className normalizedPredicate:subpredicate]; } else { @@ -578,9 +560,8 @@ + (instancetype)queryWithClassName:(NSString *)className normalizedPredicate:(NS for (NSPredicate *subpredicate in subpredicates) { if (![subpredicate isKindOfClass:[NSComparisonPredicate class]]) { // This should never happen. - [NSException raise:NSInternalInconsistencyException - format:@"A predicate had a non-comparison predicate inside an AND " - "after normalization. %@", predicate]; + PFConsistencyAssertionFailure(@"A predicate had a non-comparison predicate inside an AND after normalization. %@", + predicate); } NSComparisonPredicate *comparison = (NSComparisonPredicate *)subpredicate; [query whereComparisonPredicate:comparison]; @@ -590,9 +571,7 @@ + (instancetype)queryWithClassName:(NSString *)className normalizedPredicate:(NS case NSOrPredicateType: { NSMutableArray *subqueries = [NSMutableArray arrayWithCapacity:compound.subpredicates.count]; if (compound.subpredicates.count > 4) { - [NSException raise:NSInternalInconsistencyException - format:@"This query is too complex. It had an OR with >4 subpredicates " - "after normalization."]; + PFConsistencyAssertionFailure(@"This query is too complex. It had an OR with >4 subpredicates after normalization."); } for (NSPredicate *subpredicate in compound.subpredicates) { [subqueries addObject:[self queryWithClassName:className normalizedPredicate:subpredicate]]; @@ -602,13 +581,12 @@ + (instancetype)queryWithClassName:(NSString *)className normalizedPredicate:(NS case NSNotPredicateType: default: { // This should never happen. - [NSException raise:NSInternalInconsistencyException - format:@"A predicate had a NOT after normalization. %@", predicate]; + PFConsistencyAssertionFailure(@"A predicate had a NOT after normalization. %@", predicate); return nil; } } } else { - [NSException raise:NSInternalInconsistencyException format:@"Unknown predicate type."]; + PFConsistencyAssertionFailure(@"Unknown predicate type."); return nil; } } @@ -620,8 +598,7 @@ + (instancetype)queryWithClassName:(NSString *)className normalizedPredicate:(NS - (void)checkIfCommandIsRunning { @synchronized(self) { if (_cancellationTokenSource) { - [NSException raise:NSInternalInconsistencyException - format:@"This query has an outstanding network connection. You have to wait until it's done."]; + PFConsistencyAssertionFailure(@"This query has an outstanding network connection. You have to wait until it's done."); } } }