aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Remote
diff options
context:
space:
mode:
authorGravatar Gil <mcg@google.com>2018-05-24 11:00:23 -0700
committerGravatar GitHub <noreply@github.com>2018-05-24 11:00:23 -0700
commit8037a4bf79b8ae49162c2b6f099d62ec17a7f283 (patch)
tree5a15df8664abbcf3e63479fa3e7560fd8c2fbe9e /Firestore/Source/Remote
parentde4fe203525072babcdec444a06e42e77f0aa714 (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/Remote')
-rw-r--r--Firestore/Source/Remote/FSTDatastore.mm16
-rw-r--r--Firestore/Source/Remote/FSTOnlineStateTracker.mm12
-rw-r--r--Firestore/Source/Remote/FSTRemoteEvent.mm10
-rw-r--r--Firestore/Source/Remote/FSTRemoteStore.mm42
-rw-r--r--Firestore/Source/Remote/FSTSerializerBeta.mm106
-rw-r--r--Firestore/Source/Remote/FSTStream.mm44
6 files changed, 114 insertions, 116 deletions
diff --git a/Firestore/Source/Remote/FSTDatastore.mm b/Firestore/Source/Remote/FSTDatastore.mm
index d45af6b..5f79122 100644
--- a/Firestore/Source/Remote/FSTDatastore.mm
+++ b/Firestore/Source/Remote/FSTDatastore.mm
@@ -31,7 +31,6 @@
#import "Firestore/Source/Model/FSTMutation.h"
#import "Firestore/Source/Remote/FSTSerializerBeta.h"
#import "Firestore/Source/Remote/FSTStream.h"
-#import "Firestore/Source/Util/FSTAssert.h"
#import "Firestore/Source/Util/FSTDispatchQueue.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Firestore.pbrpc.h"
@@ -42,6 +41,7 @@
#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/error_apple.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"
@@ -130,8 +130,8 @@ typedef GRPCProtoCall * (^RPCFactory)(void);
} else if ([error.domain isEqualToString:FIRFirestoreErrorDomain]) {
return error;
} else if ([error.domain isEqualToString:kGRPCErrorDomain]) {
- FSTAssert(error.code >= GRPCErrorCodeCancelled && error.code <= GRPCErrorCodeUnauthenticated,
- @"Unknown GRPC error code: %ld", (long)error.code);
+ HARD_ASSERT(error.code >= GRPCErrorCodeCancelled && error.code <= GRPCErrorCodeUnauthenticated,
+ "Unknown GRPC error code: %s", error.code);
return
[NSError errorWithDomain:FIRFirestoreErrorDomain code:error.code userInfo:error.userInfo];
} else {
@@ -142,14 +142,14 @@ typedef GRPCProtoCall * (^RPCFactory)(void);
}
+ (BOOL)isAbortedError:(NSError *)error {
- FSTAssert([error.domain isEqualToString:FIRFirestoreErrorDomain],
- @"isAbortedError: only works with errors emitted by FSTDatastore.");
+ HARD_ASSERT([error.domain isEqualToString:FIRFirestoreErrorDomain],
+ "isAbortedError: only works with errors emitted by FSTDatastore.");
return error.code == FIRFirestoreErrorCodeAborted;
}
+ (BOOL)isPermanentWriteError:(NSError *)error {
- FSTAssert([error.domain isEqualToString:FIRFirestoreErrorDomain],
- @"isPerminanteWriteError: only works with errors emitted by FSTDatastore.");
+ HARD_ASSERT([error.domain isEqualToString:FIRFirestoreErrorDomain],
+ "isPerminanteWriteError: only works with errors emitted by FSTDatastore.");
switch (error.code) {
case FIRFirestoreErrorCodeCancelled:
case FIRFirestoreErrorCodeUnknown:
@@ -287,7 +287,7 @@ typedef GRPCProtoCall * (^RPCFactory)(void);
// Streaming response is done, call completion
LOG_DEBUG("RPC BatchGetDocuments completed successfully.");
[FSTDatastore logHeadersForRPC:rpc RPCName:@"BatchGetDocuments"];
- FSTAssert(!response, @"Got response after done.");
+ HARD_ASSERT(!response, "Got response after done.");
NSMutableArray<FSTMaybeDocument *> *docs =
[NSMutableArray arrayWithCapacity:closure->results.size()];
for (auto &&entry : closure->results) {
diff --git a/Firestore/Source/Remote/FSTOnlineStateTracker.mm b/Firestore/Source/Remote/FSTOnlineStateTracker.mm
index e512a3c..fb993e5 100644
--- a/Firestore/Source/Remote/FSTOnlineStateTracker.mm
+++ b/Firestore/Source/Remote/FSTOnlineStateTracker.mm
@@ -16,9 +16,9 @@
#import "Firestore/Source/Remote/FSTOnlineStateTracker.h"
#import "Firestore/Source/Remote/FSTRemoteStore.h"
-#import "Firestore/Source/Util/FSTAssert.h"
#import "Firestore/Source/Util/FSTDispatchQueue.h"
+#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
#include "Firestore/core/src/firebase/firestore/util/log.h"
NS_ASSUME_NONNULL_BEGIN
@@ -75,15 +75,15 @@ static const NSTimeInterval kOnlineStateTimeout = 10;
if (self.watchStreamFailures == 0) {
[self setAndBroadcastState:FSTOnlineStateUnknown];
- FSTAssert(!self.onlineStateTimer, @"onlineStateTimer shouldn't be started yet");
+ HARD_ASSERT(!self.onlineStateTimer, "onlineStateTimer shouldn't be started yet");
self.onlineStateTimer = [self.queue
dispatchAfterDelay:kOnlineStateTimeout
timerID:FSTTimerIDOnlineStateTimeout
block:^{
self.onlineStateTimer = nil;
- FSTAssert(
+ HARD_ASSERT(
self.state == FSTOnlineStateUnknown,
- @"Timer should be canceled if we transitioned to a different state.");
+ "Timer should be canceled if we transitioned to a different state.");
LOG_DEBUG(
"Watch stream didn't reach Online or Offline within %s seconds. "
"Considering client offline.",
@@ -104,8 +104,8 @@ static const NSTimeInterval kOnlineStateTimeout = 10;
// To get to FSTOnlineStateOnline, updateState: must have been called which would have reset
// our heuristics.
- FSTAssert(self.watchStreamFailures == 0, @"watchStreamFailures must be 0");
- FSTAssert(!self.onlineStateTimer, @"onlineStateTimer must be nil");
+ HARD_ASSERT(self.watchStreamFailures == 0, "watchStreamFailures must be 0");
+ HARD_ASSERT(!self.onlineStateTimer, "onlineStateTimer must be nil");
} else {
self.watchStreamFailures++;
if (self.watchStreamFailures >= kMaxWatchStreamFailures) {
diff --git a/Firestore/Source/Remote/FSTRemoteEvent.mm b/Firestore/Source/Remote/FSTRemoteEvent.mm
index ebd9b93..67af650 100644
--- a/Firestore/Source/Remote/FSTRemoteEvent.mm
+++ b/Firestore/Source/Remote/FSTRemoteEvent.mm
@@ -22,10 +22,10 @@
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Remote/FSTWatchChange.h"
-#import "Firestore/Source/Util/FSTAssert.h"
#import "Firestore/Source/Util/FSTClasses.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/hashing.h"
#include "Firestore/core/src/firebase/firestore/util/log.h"
@@ -444,14 +444,14 @@ initWithSnapshotVersion:(SnapshotVersion)snapshotVersion
}
- (void)addWatchChanges:(NSArray<FSTWatchChange *> *)watchChanges {
- FSTAssert(!self.frozen, @"Trying to modify frozen FSTWatchChangeAggregator");
+ HARD_ASSERT(!self.frozen, "Trying to modify frozen FSTWatchChangeAggregator");
for (FSTWatchChange *watchChange in watchChanges) {
[self addWatchChange:watchChange];
}
}
- (void)addWatchChange:(FSTWatchChange *)watchChange {
- FSTAssert(!self.frozen, @"Trying to modify frozen FSTWatchChangeAggregator");
+ HARD_ASSERT(!self.frozen, "Trying to modify frozen FSTWatchChangeAggregator");
if ([watchChange isKindOfClass:[FSTDocumentWatchChange class]]) {
[self addDocumentChange:(FSTDocumentWatchChange *)watchChange];
} else if ([watchChange isKindOfClass:[FSTWatchTargetChange class]]) {
@@ -459,7 +459,7 @@ initWithSnapshotVersion:(SnapshotVersion)snapshotVersion
} else if ([watchChange isKindOfClass:[FSTExistenceFilterWatchChange class]]) {
[self addExistenceFilterChange:(FSTExistenceFilterWatchChange *)watchChange];
} else {
- FSTFail(@"Unknown watch change: %@", watchChange);
+ HARD_FAIL("Unknown watch change: %s", watchChange);
}
}
@@ -561,7 +561,7 @@ initWithSnapshotVersion:(SnapshotVersion)snapshotVersion
// We need to keep track of removed targets to we can post-filter and remove any target
// changes.
[self recordResponseForTargetID:targetID];
- FSTAssert(!targetChange.cause, @"WatchChangeAggregator does not handle errored targets.");
+ HARD_ASSERT(!targetChange.cause, "WatchChangeAggregator does not handle errored targets.");
break;
case FSTWatchTargetChangeStateCurrent:
if ([self isActiveTarget:targetID]) {
diff --git a/Firestore/Source/Remote/FSTRemoteStore.mm b/Firestore/Source/Remote/FSTRemoteStore.mm
index e0adb4e..7338ffb 100644
--- a/Firestore/Source/Remote/FSTRemoteStore.mm
+++ b/Firestore/Source/Remote/FSTRemoteStore.mm
@@ -31,11 +31,11 @@
#import "Firestore/Source/Remote/FSTRemoteEvent.h"
#import "Firestore/Source/Remote/FSTStream.h"
#import "Firestore/Source/Remote/FSTWatchChange.h"
-#import "Firestore/Source/Util/FSTAssert.h"
#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
#include "Firestore/core/src/firebase/firestore/model/snapshot_version.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"
@@ -154,8 +154,8 @@ static const int kMaxPendingWrites = 10;
#pragma mark Online/Offline state
- (BOOL)isNetworkEnabled {
- FSTAssert((self.watchStream == nil) == (self.writeStream == nil),
- @"WatchStream and WriteStream should both be null or non-null");
+ HARD_ASSERT((self.watchStream == nil) == (self.writeStream == nil),
+ "WatchStream and WriteStream should both be null or non-null");
return self.watchStream != nil;
}
@@ -227,16 +227,16 @@ static const int kMaxPendingWrites = 10;
#pragma mark Watch Stream
- (void)startWatchStream {
- FSTAssert([self shouldStartWatchStream],
- @"startWatchStream: called when shouldStartWatchStream: is false.");
+ HARD_ASSERT([self shouldStartWatchStream],
+ "startWatchStream: called when shouldStartWatchStream: is false.");
[self.watchStream startWithDelegate:self];
[self.onlineStateTracker handleWatchStreamStart];
}
- (void)listenToTargetWithQueryData:(FSTQueryData *)queryData {
NSNumber *targetKey = @(queryData.targetID);
- FSTAssert(!self.listenTargets[targetKey], @"listenToQuery called with duplicate target id: %@",
- targetKey);
+ HARD_ASSERT(!self.listenTargets[targetKey], "listenToQuery called with duplicate target id: %s",
+ targetKey);
self.listenTargets[targetKey] = queryData;
@@ -255,7 +255,7 @@ static const int kMaxPendingWrites = 10;
- (void)stopListeningToTargetID:(FSTTargetID)targetID {
FSTBoxedTargetID *targetKey = @(targetID);
FSTQueryData *queryData = self.listenTargets[targetKey];
- FSTAssert(queryData, @"unlistenToTarget: target not currently watched: %@", targetKey);
+ HARD_ASSERT(queryData, "unlistenToTarget: target not currently watched: %s", targetKey);
[self.listenTargets removeObjectForKey:targetKey];
if ([self isNetworkEnabled] && [self.watchStream isOpen]) {
@@ -331,9 +331,9 @@ static const int kMaxPendingWrites = 10;
}
- (void)watchStreamWasInterruptedWithError:(nullable NSError *)error {
- FSTAssert([self isNetworkEnabled],
- @"watchStreamWasInterruptedWithError: should only be called when the network is "
- "enabled");
+ HARD_ASSERT([self isNetworkEnabled],
+ "watchStreamWasInterruptedWithError: should only be called when the network is "
+ "enabled");
[self cleanUpWatchStreamState];
[self.onlineStateTracker handleWatchStreamFailure];
@@ -388,8 +388,8 @@ static const int kMaxPendingWrites = 10;
[FSTDeletedDocument documentWithKey:key version:snapshotVersion];
[remoteEvent addDocumentUpdate:deletedDoc];
} else {
- FSTAssert(filter.count == 1, @"Single document existence filter with count: %" PRId32,
- filter.count);
+ HARD_ASSERT(filter.count == 1, "Single document existence filter with count: %s",
+ filter.count);
}
} else {
@@ -401,8 +401,8 @@ static const int kMaxPendingWrites = 10;
FSTUpdateMapping *update = (FSTUpdateMapping *)mapping;
trackedRemote = [update applyTo:trackedRemote];
} else {
- FSTAssert([mapping isKindOfClass:[FSTResetMapping class]],
- @"Expected either reset or update mapping but got something else %@", mapping);
+ HARD_ASSERT([mapping isKindOfClass:[FSTResetMapping class]],
+ "Expected either reset or update mapping but got something else %s", mapping);
trackedRemote = ((FSTResetMapping *)mapping).documents;
}
}
@@ -461,7 +461,7 @@ static const int kMaxPendingWrites = 10;
/** Process a target error and passes the error along to SyncEngine. */
- (void)processTargetErrorForWatchChange:(FSTWatchTargetChange *)change {
- FSTAssert(change.cause, @"Handling target error without a cause");
+ HARD_ASSERT(change.cause, "Handling target error without a cause");
// Ignore targets that have been removed already.
for (FSTBoxedTargetID *targetID in change.targetIDs) {
if (self.listenTargets[targetID]) {
@@ -482,8 +482,8 @@ static const int kMaxPendingWrites = 10;
}
- (void)startWriteStream {
- FSTAssert([self shouldStartWriteStream],
- @"startWriteStream: called when shouldStartWriteStream: is false.");
+ HARD_ASSERT([self shouldStartWriteStream],
+ "startWriteStream: called when shouldStartWriteStream: is false.");
[self.writeStream startWithDelegate:self];
}
@@ -526,7 +526,7 @@ static const int kMaxPendingWrites = 10;
/** Given mutations to commit, actually commits them to the backend. */
- (void)commitBatch:(FSTMutationBatch *)batch {
- FSTAssert([self canWriteMutations], @"commitBatch called when mutations can't be written");
+ HARD_ASSERT([self canWriteMutations], "commitBatch called when mutations can't be written");
self.lastBatchSeen = batch.batchID;
[self.pendingWrites addObject:batch];
@@ -590,8 +590,8 @@ static const int kMaxPendingWrites = 10;
* has been terminated by the client or the server.
*/
- (void)writeStreamWasInterruptedWithError:(nullable NSError *)error {
- FSTAssert([self isNetworkEnabled],
- @"writeStreamDidClose: should only be called when the network is enabled");
+ HARD_ASSERT([self isNetworkEnabled],
+ "writeStreamDidClose: should only be called when the network is enabled");
// If the write stream closed due to an error, invoke the error callbacks if there are pending
// writes.
diff --git a/Firestore/Source/Remote/FSTSerializerBeta.mm b/Firestore/Source/Remote/FSTSerializerBeta.mm
index f862ec3..ab40dd6 100644
--- a/Firestore/Source/Remote/FSTSerializerBeta.mm
+++ b/Firestore/Source/Remote/FSTSerializerBeta.mm
@@ -41,7 +41,6 @@
#import "Firestore/Source/Model/FSTMutationBatch.h"
#import "Firestore/Source/Remote/FSTExistenceFilter.h"
#import "Firestore/Source/Remote/FSTWatchChange.h"
-#import "Firestore/Source/Util/FSTAssert.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
@@ -51,6 +50,7 @@
#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/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"
#include "absl/types/optional.h"
@@ -128,10 +128,10 @@ NS_ASSUME_NONNULL_BEGIN
- (DocumentKey)decodedDocumentKey:(NSString *)name {
const ResourcePath path = [self decodedResourcePathWithDatabaseID:name];
- FSTAssert(path[1] == self.databaseID->project_id(),
- @"Tried to deserialize key from different project.");
- FSTAssert(path[3] == self.databaseID->database_id(),
- @"Tried to deserialize key from different datbase.");
+ HARD_ASSERT(path[1] == self.databaseID->project_id(),
+ "Tried to deserialize key from different project.");
+ HARD_ASSERT(path[3] == self.databaseID->database_id(),
+ "Tried to deserialize key from different datbase.");
return DocumentKey{[self localResourcePathForQualifiedResourcePath:path]};
}
@@ -145,8 +145,8 @@ NS_ASSUME_NONNULL_BEGIN
- (ResourcePath)decodedResourcePathWithDatabaseID:(NSString *)name {
const ResourcePath path = ResourcePath::FromString(util::MakeStringView(name));
- FSTAssert([self validQualifiedResourcePath:path], @"Tried to deserialize invalid key %s",
- path.CanonicalString().c_str());
+ HARD_ASSERT([self validQualifiedResourcePath:path], "Tried to deserialize invalid key %s",
+ path.CanonicalString());
return path;
}
@@ -172,8 +172,8 @@ NS_ASSUME_NONNULL_BEGIN
}
- (ResourcePath)localResourcePathForQualifiedResourcePath:(const ResourcePath &)resourceName {
- FSTAssert(resourceName.size() > 4 && resourceName[4] == "documents",
- @"Tried to deserialize invalid key %s", resourceName.CanonicalString().c_str());
+ HARD_ASSERT(resourceName.size() > 4 && resourceName[4] == "documents",
+ "Tried to deserialize invalid key %s", resourceName.CanonicalString());
return resourceName.PopFirst(5);
}
@@ -229,7 +229,7 @@ NS_ASSUME_NONNULL_BEGIN
return result;
} else {
- FSTFail(@"Unhandled type %@ on %@", NSStringFromClass([fieldValue class]), fieldValue);
+ HARD_FAIL("Unhandled type %s on %s", NSStringFromClass([fieldValue class]), fieldValue);
}
}
@@ -273,7 +273,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self decodedMapValue:valueProto.mapValue];
default:
- FSTFail(@"Unhandled type %d on %@", valueProto.valueTypeOneOfCase, valueProto);
+ HARD_FAIL("Unhandled type %s on %s", valueProto.valueTypeOneOfCase, valueProto);
}
}
@@ -327,9 +327,9 @@ NS_ASSUME_NONNULL_BEGIN
- (GCFSValue *)encodedReferenceValueForDatabaseID:(const DatabaseId *)databaseID
key:(const DocumentKey &)key {
- FSTAssert(*databaseID == *self.databaseID, @"Database %s:%s cannot encode reference from %s:%s",
- self.databaseID->project_id().c_str(), self.databaseID->database_id().c_str(),
- databaseID->project_id().c_str(), databaseID->database_id().c_str());
+ HARD_ASSERT(*databaseID == *self.databaseID, "Database %s:%s cannot encode reference from %s:%s",
+ self.databaseID->project_id(), self.databaseID->database_id(),
+ databaseID->project_id(), databaseID->database_id());
GCFSValue *result = [GCFSValue message];
result.referenceValue = [self encodedResourcePathForDatabaseID:databaseID path:key.path()];
return result;
@@ -342,9 +342,9 @@ NS_ASSUME_NONNULL_BEGIN
const DocumentKey key{[self localResourcePathForQualifiedResourcePath:path]};
const DatabaseId database_id(project, database);
- FSTAssert(database_id == *self.databaseID, @"Database %s:%s cannot encode reference from %s:%s",
- self.databaseID->project_id().c_str(), self.databaseID->database_id().c_str(),
- database_id.project_id().c_str(), database_id.database_id().c_str());
+ HARD_ASSERT(database_id == *self.databaseID, "Database %s:%s cannot encode reference from %s:%s",
+ self.databaseID->project_id(), self.databaseID->database_id(),
+ database_id.project_id(), database_id.database_id());
return [FSTReferenceValue referenceValue:key databaseID:self.databaseID];
}
@@ -425,27 +425,27 @@ NS_ASSUME_NONNULL_BEGIN
case GCFSBatchGetDocumentsResponse_Result_OneOfCase_Missing:
return [self decodedDeletedDocument:response];
default:
- FSTFail(@"Unknown document type: %@", response);
+ HARD_FAIL("Unknown document type: %s", response);
}
}
- (FSTDocument *)decodedFoundDocument:(GCFSBatchGetDocumentsResponse *)response {
- FSTAssert(!!response.found, @"Tried to deserialize a found document from a deleted document.");
+ HARD_ASSERT(!!response.found, "Tried to deserialize a found document from a deleted document.");
const DocumentKey key = [self decodedDocumentKey:response.found.name];
FSTObjectValue *value = [self decodedFields:response.found.fields];
SnapshotVersion version = [self decodedVersion:response.found.updateTime];
- FSTAssert(version != SnapshotVersion::None(),
- @"Got a document response with no snapshot version");
+ HARD_ASSERT(version != SnapshotVersion::None(),
+ "Got a document response with no snapshot version");
return [FSTDocument documentWithData:value key:key version:version hasLocalMutations:NO];
}
- (FSTDeletedDocument *)decodedDeletedDocument:(GCFSBatchGetDocumentsResponse *)response {
- FSTAssert(!!response.missing, @"Tried to deserialize a deleted document from a found document.");
+ HARD_ASSERT(!!response.missing, "Tried to deserialize a deleted document from a found document.");
const DocumentKey key = [self decodedDocumentKey:response.missing];
SnapshotVersion version = [self decodedVersion:response.readTime];
- FSTAssert(version != SnapshotVersion::None(),
- @"Got a no document response with no snapshot version");
+ HARD_ASSERT(version != SnapshotVersion::None(),
+ "Got a no document response with no snapshot version");
return [FSTDeletedDocument documentWithKey:key version:version];
}
@@ -480,7 +480,7 @@ NS_ASSUME_NONNULL_BEGIN
proto.delete_p = [self encodedDocumentKey:deleteMutation.key];
} else {
- FSTFail(@"Unknown mutation type %@", NSStringFromClass(mutationClass));
+ HARD_FAIL("Unknown mutation type %s", NSStringFromClass(mutationClass));
}
if (!mutation.precondition.IsNone()) {
@@ -513,8 +513,8 @@ NS_ASSUME_NONNULL_BEGIN
precondition:precondition];
case GCFSWrite_Operation_OneOfCase_Transform: {
- FSTAssert(precondition == Precondition::Exists(true),
- @"Transforms must have precondition \"exists == true\"");
+ HARD_ASSERT(precondition == Precondition::Exists(true),
+ "Transforms must have precondition \"exists == true\"");
return [[FSTTransformMutation alloc]
initWithKey:[self decodedDocumentKey:mutation.transform.document]
@@ -523,19 +523,19 @@ NS_ASSUME_NONNULL_BEGIN
default:
// Note that insert is intentionally unhandled, since we don't ever deal in them.
- FSTFail(@"Unknown mutation operation: %d", mutation.operationOneOfCase);
+ HARD_FAIL("Unknown mutation operation: %s", mutation.operationOneOfCase);
}
}
- (GCFSPrecondition *)encodedPrecondition:(const Precondition &)precondition {
- FSTAssert(!precondition.IsNone(), @"Can't serialize an empty precondition");
+ HARD_ASSERT(!precondition.IsNone(), "Can't serialize an empty precondition");
GCFSPrecondition *message = [GCFSPrecondition message];
if (precondition.type() == Precondition::Type::UpdateTime) {
message.updateTime = [self encodedVersion:precondition.update_time()];
} else if (precondition.type() == Precondition::Type::Exists) {
message.exists = precondition == Precondition::Exists(true);
} else {
- FSTFail(@"Unknown precondition: %@", precondition.description());
+ HARD_FAIL("Unknown precondition: %s", precondition.description());
}
return message;
}
@@ -552,7 +552,7 @@ NS_ASSUME_NONNULL_BEGIN
return Precondition::UpdateTime([self decodedVersion:precondition.updateTime]);
default:
- FSTFail(@"Unrecognized Precondition one-of case %@", precondition);
+ HARD_FAIL("Unrecognized Precondition one-of case %s", precondition);
}
}
@@ -599,7 +599,7 @@ NS_ASSUME_NONNULL_BEGIN
encodedArrayTransformElements:ArrayTransform::Elements(fieldTransform.transformation())];
} else {
- FSTFail(@"Unknown transform: %d type", fieldTransform.transformation().type());
+ HARD_FAIL("Unknown transform: %s type", fieldTransform.transformation().type());
}
return proto;
}
@@ -623,9 +623,9 @@ NS_ASSUME_NONNULL_BEGIN
for (GCFSDocumentTransform_FieldTransform *proto in protos) {
switch (proto.transformTypeOneOfCase) {
case GCFSDocumentTransform_FieldTransform_TransformType_OneOfCase_SetToServerValue: {
- FSTAssert(
+ HARD_ASSERT(
proto.setToServerValue == GCFSDocumentTransform_FieldTransform_ServerValue_RequestTime,
- @"Unknown transform setToServerValue: %d", proto.setToServerValue);
+ "Unknown transform setToServerValue: %s", proto.setToServerValue);
fieldTransforms.emplace_back(
FieldPath::FromServerFormat(util::MakeStringView(proto.fieldPath)),
absl::make_unique<ServerTimestampTransform>(ServerTimestampTransform::Get()));
@@ -653,7 +653,7 @@ NS_ASSUME_NONNULL_BEGIN
}
default:
- FSTFail(@"Unknown transform: %@", proto);
+ HARD_FAIL("Unknown transform: %s", proto);
}
}
@@ -711,7 +711,7 @@ NS_ASSUME_NONNULL_BEGIN
case FSTQueryPurposeLimboResolution:
return @"limbo-document";
default:
- FSTFail(@"Unrecognized query purpose: %lu", (unsigned long)purpose);
+ HARD_FAIL("Unrecognized query purpose: %s", purpose);
}
}
@@ -742,8 +742,8 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTQuery *)decodedQueryFromDocumentsTarget:(GCFSTarget_DocumentsTarget *)target {
NSArray<NSString *> *documents = target.documentsArray;
- FSTAssert(documents.count == 1, @"DocumentsTarget contained other than 1 document %lu",
- (unsigned long)documents.count);
+ HARD_ASSERT(documents.count == 1, "DocumentsTarget contained other than 1 document %s",
+ (unsigned long)documents.count);
NSString *name = documents[0];
return [FSTQuery queryWithPath:[self decodedQueryPath:name]];
@@ -756,7 +756,7 @@ NS_ASSUME_NONNULL_BEGIN
queryTarget.parent = [self encodedQueryPath:query.path];
} else {
const ResourcePath &path = query.path;
- FSTAssert(path.size() % 2 != 0, @"Document queries with filters are not supported.");
+ HARD_ASSERT(path.size() % 2 != 0, "Document queries with filters are not supported.");
queryTarget.parent = [self encodedQueryPath:path.PopLast()];
GCFSStructuredQuery_CollectionSelector *from = [GCFSStructuredQuery_CollectionSelector message];
from.collectionId = util::WrapNSString(path.last_segment());
@@ -795,8 +795,8 @@ NS_ASSUME_NONNULL_BEGIN
GCFSStructuredQuery *query = target.structuredQuery;
NSUInteger fromCount = query.fromArray_Count;
if (fromCount > 0) {
- FSTAssert(fromCount == 1,
- @"StructuredQuery.from with more than one collection is not supported.");
+ HARD_ASSERT(fromCount == 1,
+ "StructuredQuery.from with more than one collection is not supported.");
GCFSStructuredQuery_CollectionSelector *from = query.fromArray[0];
path = path.Append(util::MakeString(from.collectionId));
@@ -870,8 +870,8 @@ NS_ASSUME_NONNULL_BEGIN
NSArray<GCFSStructuredQuery_Filter *> *filters;
if (proto.filterTypeOneOfCase ==
GCFSStructuredQuery_Filter_FilterType_OneOfCase_CompositeFilter) {
- FSTAssert(proto.compositeFilter.op == GCFSStructuredQuery_CompositeFilter_Operator_And,
- @"Only AND-type composite filters are supported, got %d", proto.compositeFilter.op);
+ HARD_ASSERT(proto.compositeFilter.op == GCFSStructuredQuery_CompositeFilter_Operator_And,
+ "Only AND-type composite filters are supported, got %s", proto.compositeFilter.op);
filters = proto.compositeFilter.filtersArray;
} else {
filters = @[ proto ];
@@ -880,7 +880,7 @@ NS_ASSUME_NONNULL_BEGIN
for (GCFSStructuredQuery_Filter *filter in filters) {
switch (filter.filterTypeOneOfCase) {
case GCFSStructuredQuery_Filter_FilterType_OneOfCase_CompositeFilter:
- FSTFail(@"Nested composite filters are not supported");
+ HARD_FAIL("Nested composite filters are not supported");
case GCFSStructuredQuery_Filter_FilterType_OneOfCase_FieldFilter:
[result addObject:[self decodedRelationFilter:filter.fieldFilter]];
@@ -891,7 +891,7 @@ NS_ASSUME_NONNULL_BEGIN
break;
default:
- FSTFail(@"Unrecognized Filter.filterType %d", filter.filterTypeOneOfCase);
+ HARD_FAIL("Unrecognized Filter.filterType %s", filter.filterTypeOneOfCase);
}
}
return result;
@@ -921,7 +921,7 @@ NS_ASSUME_NONNULL_BEGIN
} else if ([filter isKindOfClass:[FSTNullFilter class]]) {
proto.unaryFilter.op = GCFSStructuredQuery_UnaryFilter_Operator_IsNull;
} else {
- FSTFail(@"Unrecognized filter: %@", filter);
+ HARD_FAIL("Unrecognized filter: %s", static_cast<id>(filter));
}
return proto;
}
@@ -936,7 +936,7 @@ NS_ASSUME_NONNULL_BEGIN
return [[FSTNullFilter alloc] initWithField:field];
default:
- FSTFail(@"Unrecognized UnaryFilter.operator %d", proto.op);
+ HARD_FAIL("Unrecognized UnaryFilter.operator %s", proto.op);
}
}
@@ -962,7 +962,7 @@ NS_ASSUME_NONNULL_BEGIN
case FSTRelationFilterOperatorArrayContains:
return GCFSStructuredQuery_FieldFilter_Operator_ArrayContains;
default:
- FSTFail(@"Unhandled FSTRelationFilterOperator: %ld", (long)filterOperator);
+ HARD_FAIL("Unhandled FSTRelationFilterOperator: %s", filterOperator);
}
}
@@ -982,7 +982,7 @@ NS_ASSUME_NONNULL_BEGIN
case GCFSStructuredQuery_FieldFilter_Operator_ArrayContains:
return FSTRelationFilterOperatorArrayContains;
default:
- FSTFail(@"Unhandled FieldFilter.operator: %d", filterOperator);
+ HARD_FAIL("Unhandled FieldFilter.operator: %s", filterOperator);
}
}
@@ -1026,7 +1026,7 @@ NS_ASSUME_NONNULL_BEGIN
ascending = NO;
break;
default:
- FSTFail(@"Unrecognized GCFSStructuredQuery_Direction %d", proto.direction);
+ HARD_FAIL("Unrecognized GCFSStructuredQuery_Direction %s", proto.direction);
}
return [FSTSortOrder sortOrderWithFieldPath:fieldPath ascending:ascending];
}
@@ -1074,7 +1074,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self decodedExistenceFilterWatchChange:watchChange.filter];
default:
- FSTFail(@"Unknown WatchChange.changeType %" PRId32, watchChange.responseTypeOneOfCase);
+ HARD_FAIL("Unknown WatchChange.changeType %s", watchChange.responseTypeOneOfCase);
}
}
@@ -1127,7 +1127,7 @@ NS_ASSUME_NONNULL_BEGIN
case GCFSTargetChange_TargetChangeType_Reset:
return FSTWatchTargetChangeStateReset;
default:
- FSTFail(@"Unexpected TargetChange.state: %" PRId32, state);
+ HARD_FAIL("Unexpected TargetChange.state: %s", state);
}
}
@@ -1143,7 +1143,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTObjectValue *value = [self decodedFields:change.document.fields];
const DocumentKey key = [self decodedDocumentKey:change.document.name];
SnapshotVersion version = [self decodedVersion:change.document.updateTime];
- FSTAssert(version != SnapshotVersion::None(), @"Got a document change with no snapshot version");
+ HARD_ASSERT(version != SnapshotVersion::None(), "Got a document change with no snapshot version");
FSTMaybeDocument *document =
[FSTDocument documentWithData:value key:key version:version hasLocalMutations:NO];
diff --git a/Firestore/Source/Remote/FSTStream.mm b/Firestore/Source/Remote/FSTStream.mm
index 0e45418..3a6c035 100644
--- a/Firestore/Source/Remote/FSTStream.mm
+++ b/Firestore/Source/Remote/FSTStream.mm
@@ -26,7 +26,6 @@
#import "Firestore/Source/Remote/FSTExponentialBackoff.h"
#import "Firestore/Source/Remote/FSTSerializerBeta.h"
#import "Firestore/Source/Remote/FSTStream.h"
-#import "Firestore/Source/Util/FSTAssert.h"
#import "Firestore/Source/Util/FSTClasses.h"
#import "Firestore/Source/Util/FSTDispatchQueue.h"
@@ -37,6 +36,7 @@
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
#include "Firestore/core/src/firebase/firestore/util/error_apple.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"
@@ -259,10 +259,10 @@ static const NSTimeInterval kIdleTimeout = 60.0;
}
LOG_DEBUG("%s %s start", NSStringFromClass([self class]), (__bridge void *)self);
- FSTAssert(self.state == FSTStreamStateInitial, @"Already started");
+ HARD_ASSERT(self.state == FSTStreamStateInitial, "Already started");
self.state = FSTStreamStateAuth;
- FSTAssert(_delegate == nil, @"Delegate must be nil");
+ HARD_ASSERT(_delegate == nil, "Delegate must be nil");
_delegate = delegate;
_credentials->GetToken(
@@ -281,8 +281,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
// Streams can be stopped while waiting for authorization.
return;
}
- FSTAssert(self.state == FSTStreamStateAuth, @"State should still be auth (was %ld)",
- (long)self.state);
+ HARD_ASSERT(self.state == FSTStreamStateAuth, "State should still be auth (was %s)", self.state);
// TODO(mikelehen): We should force a refresh if the previous RPC failed due to an expired token,
// but I'm not sure how to detect that right now. http://b/32762461
@@ -301,7 +300,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
prepareHeadersForRPC:_rpc
databaseID:&self.databaseInfo->database_id()
token:(token.user().is_authenticated() ? token.token() : absl::string_view())];
- FSTAssert(_callbackFilter == nil, @"GRX Filter must be nil");
+ HARD_ASSERT(_callbackFilter == nil, "GRX Filter must be nil");
_callbackFilter = [[FSTCallbackFilter alloc] initWithStream:self];
[_rpc startWithWriteable:_callbackFilter];
@@ -314,7 +313,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
LOG_DEBUG("%s %s backoff", NSStringFromClass([self class]), (__bridge void *)self);
[self.workerDispatchQueue verifyIsCurrentQueue];
- FSTAssert(self.state == FSTStreamStateError, @"Should only perform backoff in an error case");
+ HARD_ASSERT(self.state == FSTStreamStateError, "Should only perform backoff in an error case");
self.state = FSTStreamStateBackoff;
FSTWeakify(self);
@@ -334,13 +333,13 @@ static const NSTimeInterval kIdleTimeout = 60.0;
// In order to have performed a backoff the stream must have been in an error state just prior
// to entering the backoff state. If we weren't stopped we must be in the backoff state.
- FSTAssert(self.state == FSTStreamStateBackoff, @"State should still be backoff (was %ld)",
- (long)self.state);
+ HARD_ASSERT(self.state == FSTStreamStateBackoff, "State should still be backoff (was %s)",
+ self.state);
// Momentarily set state to FSTStreamStateInitial as `start` expects it.
self.state = FSTStreamStateInitial;
[self startWithDelegate:delegate];
- FSTAssert([self isStarted], @"Stream should have started.");
+ HARD_ASSERT([self isStarted], "Stream should have started.");
}
/**
@@ -365,8 +364,8 @@ static const NSTimeInterval kIdleTimeout = 60.0;
* @param error the NSError the connection was closed with.
*/
- (void)closeWithFinalState:(FSTStreamState)finalState error:(nullable NSError *)error {
- FSTAssert(finalState == FSTStreamStateError || error == nil,
- @"Can't provide an error when not in an error state.");
+ HARD_ASSERT(finalState == FSTStreamStateError || error == nil,
+ "Can't provide an error when not in an error state.");
[self.workerDispatchQueue verifyIsCurrentQueue];
@@ -433,8 +432,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
}
- (void)inhibitBackoff {
- FSTAssert(![self isStarted], @"Can only inhibit backoff after an error (was %ld)",
- (long)self.state);
+ HARD_ASSERT(![self isStarted], "Can only inhibit backoff after an error (was %s)", self.state);
[self.workerDispatchQueue verifyIsCurrentQueue];
// Clear the error condition.
@@ -551,7 +549,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
*/
- (void)handleStreamClose:(nullable NSError *)error {
LOG_DEBUG("%s %s close: %s", NSStringFromClass([self class]), (__bridge void *)self, error);
- FSTAssert([self isStarted], @"handleStreamClose: called for non-started stream.");
+ HARD_ASSERT([self isStarted], "handleStreamClose: called for non-started stream.");
// In theory the stream could close cleanly, however, in our current model we never expect this
// to happen because if we stop a stream ourselves, this callback will never be called. To
@@ -572,7 +570,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
*/
- (void)writeValue:(id)value {
[self.workerDispatchQueue enterCheckedOperation:^{
- FSTAssert([self isStarted], @"writeValue: called for stopped stream.");
+ HARD_ASSERT([self isStarted], "writeValue: called for stopped stream.");
if (!self.messageReceived) {
self.messageReceived = YES;
@@ -606,7 +604,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
- (void)writesFinishedWithError:(nullable NSError *)error __used {
error = [FSTDatastore firestoreErrorForError:error];
[self.workerDispatchQueue enterCheckedOperation:^{
- FSTAssert([self isStarted], @"writesFinishedWithError: called for stopped stream.");
+ HARD_ASSERT([self isStarted], "writesFinishedWithError: called for stopped stream.");
[self handleStreamClose:error];
}];
@@ -657,7 +655,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
}
- (void)watchQuery:(FSTQueryData *)query {
- FSTAssert([self isOpen], @"Not yet open");
+ HARD_ASSERT([self isOpen], "Not yet open");
[self.workerDispatchQueue verifyIsCurrentQueue];
GCFSListenRequest *request = [GCFSListenRequest message];
@@ -670,7 +668,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
}
- (void)unwatchTargetID:(FSTTargetID)targetID {
- FSTAssert([self isOpen], @"Not yet open");
+ HARD_ASSERT([self isOpen], "Not yet open");
[self.workerDispatchQueue verifyIsCurrentQueue];
GCFSListenRequest *request = [GCFSListenRequest message];
@@ -756,8 +754,8 @@ static const NSTimeInterval kIdleTimeout = 60.0;
- (void)writeHandshake {
// The initial request cannot contain mutations, but must contain a projectID.
- FSTAssert([self isOpen], @"Not yet open");
- FSTAssert(!self.handshakeComplete, @"Handshake sent out of turn");
+ HARD_ASSERT([self isOpen], "Not yet open");
+ HARD_ASSERT(!self.handshakeComplete, "Handshake sent out of turn");
[self.workerDispatchQueue verifyIsCurrentQueue];
GCFSWriteRequest *request = [GCFSWriteRequest message];
@@ -770,8 +768,8 @@ static const NSTimeInterval kIdleTimeout = 60.0;
}
- (void)writeMutations:(NSArray<FSTMutation *> *)mutations {
- FSTAssert([self isOpen], @"Not yet open");
- FSTAssert(self.handshakeComplete, @"Mutations sent out of turn");
+ HARD_ASSERT([self isOpen], "Not yet open");
+ HARD_ASSERT(self.handshakeComplete, "Mutations sent out of turn");
[self.workerDispatchQueue verifyIsCurrentQueue];
NSMutableArray<GCFSWrite *> *protos = [NSMutableArray arrayWithCapacity:mutations.count];