diff options
author | Gil <mcg@google.com> | 2018-05-24 11:00:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-24 11:00:23 -0700 |
commit | 8037a4bf79b8ae49162c2b6f099d62ec17a7f283 (patch) | |
tree | 5a15df8664abbcf3e63479fa3e7560fd8c2fbe9e /Firestore/Source/API | |
parent | de4fe203525072babcdec444a06e42e77f0aa714 (diff) |
Replace Objective-C assertions with C++ assertions (#1327)
* Migrate FSTFail to HARD_FAIL
* FSTCFail -> HARD_FAIL
* FSTCAssert -> HARD_ASSERT
* FSTAssert -> HARD_ASSERT
* Replace FSTAssert with NSAssert in dead Objective-C code
* Remove FSTAssert.h
Diffstat (limited to 'Firestore/Source/API')
-rw-r--r-- | Firestore/Source/API/FIRCollectionReference.mm | 3 | ||||
-rw-r--r-- | Firestore/Source/API/FIRDocumentChange.mm | 17 | ||||
-rw-r--r-- | Firestore/Source/API/FIRDocumentReference.mm | 4 | ||||
-rw-r--r-- | Firestore/Source/API/FIRDocumentSnapshot.mm | 6 | ||||
-rw-r--r-- | Firestore/Source/API/FIRFirestore.mm | 8 | ||||
-rw-r--r-- | Firestore/Source/API/FIRQuery.mm | 2 | ||||
-rw-r--r-- | Firestore/Source/API/FIRQuerySnapshot.mm | 3 | ||||
-rw-r--r-- | Firestore/Source/API/FIRTransaction.mm | 7 | ||||
-rw-r--r-- | Firestore/Source/API/FSTUserDataConverter.mm | 24 |
9 files changed, 38 insertions, 36 deletions
diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm index 3f1559e..dc157ed 100644 --- a/Firestore/Source/API/FIRCollectionReference.mm +++ b/Firestore/Source/API/FIRCollectionReference.mm @@ -23,7 +23,6 @@ #import "Firestore/Source/API/FIRQuery+Internal.h" #import "Firestore/Source/API/FIRQuery_Init.h" #import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTUsageValidation.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" @@ -68,7 +67,7 @@ NS_ASSUME_NONNULL_BEGIN // Override the designated initializer from the super class. - (instancetype)initWithQuery:(FSTQuery *)query firestore:(FIRFirestore *)firestore { - FSTFail(@"Use FIRCollectionReference initWithPath: initializer."); + HARD_FAIL("Use FIRCollectionReference initWithPath: initializer."); } // NSObject Methods diff --git a/Firestore/Source/API/FIRDocumentChange.mm b/Firestore/Source/API/FIRDocumentChange.mm index 7bb24d2..0b1413f 100644 --- a/Firestore/Source/API/FIRDocumentChange.mm +++ b/Firestore/Source/API/FIRDocumentChange.mm @@ -21,7 +21,8 @@ #import "Firestore/Source/Core/FSTViewSnapshot.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Util/FSTAssert.h" + +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" NS_ASSUME_NONNULL_BEGIN @@ -45,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN } else if (change.type == FSTDocumentViewChangeTypeRemoved) { return FIRDocumentChangeTypeRemoved; } else { - FSTFail(@"Unknown FSTDocumentViewChange: %ld", (long)change.type); + HARD_FAIL("Unknown FSTDocumentViewChange: %s", change.type); } } @@ -64,11 +65,11 @@ NS_ASSUME_NONNULL_BEGIN documentKey:change.document.key document:change.document fromCache:snapshot.isFromCache]; - FSTAssert(change.type == FSTDocumentViewChangeTypeAdded, - @"Invalid event type for first snapshot"); - FSTAssert(!lastDocument || - snapshot.query.comparator(lastDocument, change.document) == NSOrderedAscending, - @"Got added events in wrong order"); + HARD_ASSERT(change.type == FSTDocumentViewChangeTypeAdded, + "Invalid event type for first snapshot"); + HARD_ASSERT(!lastDocument || snapshot.query.comparator(lastDocument, change.document) == + NSOrderedAscending, + "Got added events in wrong order"); [changes addObject:[[FIRDocumentChange alloc] initWithType:FIRDocumentChangeTypeAdded document:document oldIndex:NSNotFound @@ -95,7 +96,7 @@ NS_ASSUME_NONNULL_BEGIN NSUInteger newIndex = NSNotFound; if (change.type != FSTDocumentViewChangeTypeAdded) { oldIndex = [indexTracker indexOfKey:change.document.key]; - FSTAssert(oldIndex != NSNotFound, @"Index for document not found"); + HARD_ASSERT(oldIndex != NSNotFound, "Index for document not found"); indexTracker = [indexTracker documentSetByRemovingKey:change.document.key]; } if (change.type != FSTDocumentViewChangeTypeRemoved) { diff --git a/Firestore/Source/API/FIRDocumentReference.mm b/Firestore/Source/API/FIRDocumentReference.mm index 5ad606c..b83f3cb 100644 --- a/Firestore/Source/API/FIRDocumentReference.mm +++ b/Firestore/Source/API/FIRDocumentReference.mm @@ -36,13 +36,13 @@ #import "Firestore/Source/Model/FSTDocumentSet.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTAsyncQueryListener.h" #import "Firestore/Source/Util/FSTUsageValidation.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/precondition.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; @@ -269,7 +269,7 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions return; } - FSTAssert(snapshot.documents.count <= 1, @"Too many document returned on a document query"); + HARD_ASSERT(snapshot.documents.count <= 1, "Too many document returned on a document query"); FSTDocument *document = [snapshot.documents documentForKey:key]; FIRDocumentSnapshot *result = [FIRDocumentSnapshot snapshotWithFirestore:firestore diff --git a/Firestore/Source/API/FIRDocumentSnapshot.mm b/Firestore/Source/API/FIRDocumentSnapshot.mm index 388b3b3..dff5b7f 100644 --- a/Firestore/Source/API/FIRDocumentSnapshot.mm +++ b/Firestore/Source/API/FIRDocumentSnapshot.mm @@ -26,11 +26,11 @@ #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTFieldValue.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTUsageValidation.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; @@ -275,7 +275,7 @@ static FSTServerTimestampBehavior InternalServerTimestampBehavor( - (NSDictionary<NSString *, id> *)data { NSDictionary<NSString *, id> *data = [super data]; - FSTAssert(data, @"Document in a QueryDocumentSnapshot should exist"); + HARD_ASSERT(data, "Document in a QueryDocumentSnapshot should exist"); return data; } @@ -283,7 +283,7 @@ static FSTServerTimestampBehavior InternalServerTimestampBehavor( (FIRServerTimestampBehavior)serverTimestampBehavior { NSDictionary<NSString *, id> *data = [super dataWithServerTimestampBehavior:serverTimestampBehavior]; - FSTAssert(data, @"Document in a QueryDocumentSnapshot should exist"); + HARD_ASSERT(data, "Document in a QueryDocumentSnapshot should exist"); return data; } diff --git a/Firestore/Source/API/FIRFirestore.mm b/Firestore/Source/API/FIRFirestore.mm index 0ed9082..3671b51 100644 --- a/Firestore/Source/API/FIRFirestore.mm +++ b/Firestore/Source/API/FIRFirestore.mm @@ -32,7 +32,6 @@ #import "Firestore/Source/API/FIRWriteBatch+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTFirestoreClient.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" #import "Firestore/Source/Util/FSTUsageValidation.h" @@ -41,6 +40,7 @@ #include "Firestore/core/src/firebase/firestore/core/database_info.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/log.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "absl/memory/memory.h" @@ -158,7 +158,7 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain"; FIRFirestore *firestore = instances[key]; if (!firestore) { NSString *projectID = app.options.projectID; - FSTAssert(projectID, @"FirebaseOptions.projectID cannot be nil."); + HARD_ASSERT(projectID, "FirebaseOptions.projectID cannot be nil."); FSTDispatchQueue *workerDispatchQueue = [FSTDispatchQueue queueWith:dispatch_queue_create("com.google.firebase.firestore", DISPATCH_QUEUE_SERIAL)]; @@ -242,8 +242,8 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain"; @synchronized(self) { if (!_client) { // These values are validated elsewhere; this is just double-checking: - FSTAssert(_settings.host, @"FirestoreSettings.host cannot be nil."); - FSTAssert(_settings.dispatchQueue, @"FirestoreSettings.dispatchQueue cannot be nil."); + HARD_ASSERT(_settings.host, "FirestoreSettings.host cannot be nil."); + HARD_ASSERT(_settings.dispatchQueue, "FirestoreSettings.dispatchQueue cannot be nil."); if (!_settings.timestampsInSnapshotsEnabled) { LOG_WARN( diff --git a/Firestore/Source/API/FIRQuery.mm b/Firestore/Source/API/FIRQuery.mm index ad4d2aa..08c912d 100644 --- a/Firestore/Source/API/FIRQuery.mm +++ b/Firestore/Source/API/FIRQuery.mm @@ -34,13 +34,13 @@ #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTFieldValue.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTAsyncQueryListener.h" #import "Firestore/Source/Util/FSTUsageValidation.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; diff --git a/Firestore/Source/API/FIRQuerySnapshot.mm b/Firestore/Source/API/FIRQuerySnapshot.mm index fb7a849..7a6018b 100644 --- a/Firestore/Source/API/FIRQuerySnapshot.mm +++ b/Firestore/Source/API/FIRQuerySnapshot.mm @@ -25,7 +25,8 @@ #import "Firestore/Source/Core/FSTViewSnapshot.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Util/FSTAssert.h" + +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Source/API/FIRTransaction.mm b/Firestore/Source/API/FIRTransaction.mm index b5bdefa..8eb82bb 100644 --- a/Firestore/Source/API/FIRTransaction.mm +++ b/Firestore/Source/API/FIRTransaction.mm @@ -22,9 +22,10 @@ #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTTransaction.h" #import "Firestore/Source/Model/FSTDocument.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTUsageValidation.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" + NS_ASSUME_NONNULL_BEGIN #pragma mark - FIRTransaction @@ -111,8 +112,8 @@ NS_ASSUME_NONNULL_BEGIN completion(nil, error); return; } - FSTAssert(documents.count == 1, - @"Mismatch in docs returned from document lookup."); + HARD_ASSERT(documents.count == 1, + "Mismatch in docs returned from document lookup."); FSTMaybeDocument *internalDoc = documents.firstObject; if ([internalDoc isKindOfClass:[FSTDeletedDocument class]]) { completion(nil, nil); diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm index 3484539..44e46da 100644 --- a/Firestore/Source/API/FSTUserDataConverter.mm +++ b/Firestore/Source/API/FSTUserDataConverter.mm @@ -29,7 +29,6 @@ #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTUsageValidation.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" @@ -39,6 +38,7 @@ #include "Firestore/core/src/firebase/firestore/model/field_transform.h" #include "Firestore/core/src/firebase/firestore/model/precondition.h" #include "Firestore/core/src/firebase/firestore/model/transform_operations.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "absl/memory/memory.h" @@ -532,8 +532,8 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { [FSTParseContext contextWithSource:FSTUserDataSourceArgument path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())]; FSTFieldValue *_Nullable parsed = [self parseData:input context:context]; - FSTAssert(parsed, @"Parsed data should not be nil."); - FSTAssert(context.fieldTransforms->empty(), @"Field transforms should have been disallowed."); + HARD_ASSERT(parsed, "Parsed data should not be nil."); + HARD_ASSERT(context.fieldTransforms->empty(), "Field transforms should have been disallowed."); return parsed; } @@ -626,8 +626,8 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { // deleted. [context appendToFieldMaskWithFieldPath:*context.path]; } else if (context.dataSource == FSTUserDataSourceUpdate) { - FSTAssert(context.path->size() > 0, - @"FieldValue.delete() at the top level should have already been handled."); + HARD_ASSERT(context.path->size() > 0, + "FieldValue.delete() at the top level should have already been handled."); FSTThrowInvalidArgument( @"FieldValue.delete() can only appear at the top level of your " "update data%@", @@ -662,7 +662,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { transformOperation:std::move(array_remove)]; } else { - FSTFail(@"Unknown FIRFieldValue type: %@", NSStringFromClass([fieldValue class])); + HARD_FAIL("Unknown FIRFieldValue type: %s", NSStringFromClass([fieldValue class])); } } @@ -741,7 +741,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { default: // All documented codes should be handled above, so this shouldn't happen. - FSTCFail(@"Unknown NSNumber objCType %s on %@", cType, input); + HARD_FAIL("Unknown NSNumber objCType %s on %s", cType, input); } } else if ([input isKindOfClass:[NSString class]]) { @@ -780,8 +780,8 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { if (context.dataSource == FSTUserDataSourceMergeSet) { return nil; } else if (context.dataSource == FSTUserDataSourceUpdate) { - FSTAssert(context.path->size() > 0, - @"FieldValue.delete() at the top level should have already been handled."); + HARD_ASSERT(context.path->size() > 0, + "FieldValue.delete() at the top level should have already been handled."); FSTThrowInvalidArgument( @"FieldValue.delete() can only appear at the top level of your update data%@", [context fieldDescription]); @@ -808,7 +808,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { // Return nil so this value is omitted from the parsed result. return nil; } else { - FSTFail(@"Unknown FIRFieldValue type: %@", NSStringFromClass([input class])); + HARD_FAIL("Unknown FIRFieldValue type: %s", NSStringFromClass([input class])); } } else { @@ -828,8 +828,8 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())]; FSTFieldValue *parsedElement = [self parseData:element context:[context contextForArrayIndex:i]]; - FSTAssert(parsedElement && context.fieldTransforms->size() == 0, - @"Failed to properly parse array transform element: %@", element); + HARD_ASSERT(parsedElement && context.fieldTransforms->size() == 0, + "Failed to properly parse array transform element: %s", element); results.push_back(parsedElement); } return results; |