Skip to content

Commit 8633f5f

Browse files
authored
Make sure every member of Error enum has the kError prefix (#5546)
This is for consistency with other Firebase C++ SDKs (e.g. [RTDB](https://github.com/firebase/firebase-cpp-sdk/blob/d0fc238bb866c92ed4241b55ddd82c8cf87867cd/database/src/include/firebase/database/common.h#L24-L60)).
1 parent 3459704 commit 8633f5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+281
-276
lines changed

Firestore/core/include/firebase/firestore/firestore_errors.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ namespace firestore {
2828
enum Error {
2929
/** The operation completed successfully. */
3030
// Note: NSError objects will never have a code with this value.
31-
kOk = 0,
31+
kErrorOk = 0,
3232

3333
/** The operation was cancelled (typically by the caller). */
34-
kCancelled = 1,
34+
kErrorCancelled = 1,
3535

3636
/** Unknown error or an error from a different error domain. */
37-
kUnknown = 2,
37+
kErrorUnknown = 2,
3838

3939
/**
4040
* Client specified an invalid argument. Note that this differs from
4141
* FailedPrecondition. InvalidArgument indicates arguments that are
4242
* problematic regardless of the state of the system (e.g., an invalid field
4343
* name).
4444
*/
45-
kInvalidArgument = 3,
45+
kErrorInvalidArgument = 3,
4646

4747
/**
4848
* Deadline expired before operation could complete. For operations that
@@ -51,61 +51,61 @@ enum Error {
5151
* from a server could have been delayed long enough for the deadline to
5252
* expire.
5353
*/
54-
kDeadlineExceeded = 4,
54+
kErrorDeadlineExceeded = 4,
5555

5656
/** Some requested document was not found. */
57-
kNotFound = 5,
57+
kErrorNotFound = 5,
5858

5959
/** Some document that we attempted to create already exists. */
60-
kAlreadyExists = 6,
60+
kErrorAlreadyExists = 6,
6161

6262
/** The caller does not have permission to execute the specified operation. */
63-
kPermissionDenied = 7,
63+
kErrorPermissionDenied = 7,
6464

6565
/**
6666
* Some resource has been exhausted, perhaps a per-user quota, or perhaps the
6767
* entire file system is out of space.
6868
*/
69-
kResourceExhausted = 8,
69+
kErrorResourceExhausted = 8,
7070

7171
/**
7272
* Operation was rejected because the system is not in a state required for
7373
* the operation's execution.
7474
*/
75-
kFailedPrecondition = 9,
75+
kErrorFailedPrecondition = 9,
7676

7777
/**
7878
* The operation was aborted, typically due to a concurrency issue like
7979
* transaction aborts, etc.
8080
*/
81-
kAborted = 10,
81+
kErrorAborted = 10,
8282

8383
/** Operation was attempted past the valid range. */
84-
kOutOfRange = 11,
84+
kErrorOutOfRange = 11,
8585

8686
/** Operation is not implemented or not supported/enabled. */
87-
kUnimplemented = 12,
87+
kErrorUnimplemented = 12,
8888

8989
/**
9090
* Internal errors. Means some invariants expected by underlying system has
9191
* been broken. If you see one of these errors, something is very broken.
9292
*/
93-
kInternal = 13,
93+
kErrorInternal = 13,
9494

9595
/**
9696
* The service is currently unavailable. This is a most likely a transient
9797
* condition and may be corrected by retrying with a backoff.
9898
*/
99-
kUnavailable = 14,
99+
kErrorUnavailable = 14,
100100

101101
/** Unrecoverable data loss or corruption. */
102-
kDataLoss = 15,
102+
kErrorDataLoss = 15,
103103

104104
/**
105105
* The request does not have valid authentication credentials for the
106106
* operation.
107107
*/
108-
kUnauthenticated = 16
108+
kErrorUnauthenticated = 16
109109
};
110110

111111
} // namespace firestore

Firestore/core/src/api/document_reference.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ void DocumentReference::GetDocument(Source source,
153153
// 2) Actually call the callback with an error if the
154154
// document doesn't exist when you are offline.
155155
listener_->OnEvent(
156-
Status{Error::kUnavailable,
156+
Status{Error::kErrorUnavailable,
157157
"Failed to get document because the client is offline."});
158158
} else if (snapshot.exists() && snapshot.metadata().from_cache() &&
159159
source_ == Source::Server) {
160160
listener_->OnEvent(
161-
Status{Error::kUnavailable,
161+
Status{Error::kErrorUnavailable,
162162
"Failed to get document from server. (However, "
163163
"this document does exist in the local cache. Run "
164164
"again without setting source to "

Firestore/core/src/api/firestore.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void Firestore::ClearPersistence(util::StatusCallback callback) {
167167
std::lock_guard<std::mutex> lock{mutex_};
168168
if (client_ && !client()->is_terminated()) {
169169
Yield(util::Status(
170-
Error::kFailedPrecondition,
170+
Error::kErrorFailedPrecondition,
171171
"Persistence cannot be cleared while the client is running."));
172172
return;
173173
}

Firestore/core/src/api/query_core.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void Query::GetDocuments(Source source, QuerySnapshotListener&& callback) {
109109

110110
if (snapshot.metadata().from_cache() && source_ == Source::Server) {
111111
listener_->OnEvent(Status{
112-
Error::kUnavailable,
112+
Error::kErrorUnavailable,
113113
"Failed to get documents from server. (However, these documents "
114114
"may exist in the local cache. Run again without setting source to "
115115
"FirestoreSourceServer to retrieve the cached documents.)"});

Firestore/core/src/auth/firebase_credentials_provider_apple.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
// Cancel the request since the user changed while the request was
9898
// outstanding so the response is likely for a previous user (which
9999
// user, we can't be sure).
100-
completion(util::Status(Error::kAborted,
100+
completion(util::Status(Error::kErrorAborted,
101101
"GetToken aborted due to token change."));
102102
} else {
103103
if (error == nil) {
@@ -107,7 +107,7 @@
107107
completion(Token::Unauthenticated());
108108
}
109109
} else {
110-
Error error_code = Error::kUnknown;
110+
Error error_code = Error::kErrorUnknown;
111111
if (error.domain == FIRFirestoreErrorDomain) {
112112
error_code = static_cast<Error>(error.code);
113113
}

Firestore/core/src/core/firestore_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void FirestoreClient::GetDocumentFromLocalCache(
382382
/*from_cache=*/true});
383383
} else {
384384
maybe_snapshot =
385-
Status{Error::kUnavailable,
385+
Status{Error::kErrorUnavailable,
386386
"Failed to get document from cache. (However, this document "
387387
"may exist on the server. Run again without setting source to "
388388
"FirestoreSourceCache to attempt to retrieve the document "};

Firestore/core/src/core/sync_engine.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ const ListenSequenceNumber kIrrelevantSequenceNumber = -1;
7272

7373
bool ErrorIsInteresting(const Status& error) {
7474
bool missing_index =
75-
(error.code() == Error::kFailedPrecondition &&
75+
(error.code() == Error::kErrorFailedPrecondition &&
7676
error.error_message().find("requires an index") != std::string::npos);
77-
bool no_permission = (error.code() == Error::kPermissionDenied);
77+
bool no_permission = (error.code() == Error::kErrorPermissionDenied);
7878
return missing_index || no_permission;
7979
}
8080

@@ -448,7 +448,7 @@ void SyncEngine::FailOutstandingPendingWriteCallbacks(
448448
const std::string& message) {
449449
for (const auto& entry : pending_writes_callbacks_) {
450450
for (const auto& callback : entry.second) {
451-
callback(Status(Error::kCancelled, message));
451+
callback(Status(Error::kErrorCancelled, message));
452452
}
453453
}
454454

Firestore/core/src/core/transaction.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Status Transaction::RecordVersion(const MaybeDocument& doc) {
6767
if (existing_version.has_value()) {
6868
if (doc_version != existing_version.value()) {
6969
// This transaction will fail no matter what.
70-
return Status{Error::kAborted,
70+
return Status{Error::kErrorAborted,
7171
"Document version changed between two reads."};
7272
}
7373
return Status::OK();
@@ -82,7 +82,7 @@ void Transaction::Lookup(const std::vector<DocumentKey>& keys,
8282
EnsureCommitNotCalled();
8383

8484
if (!mutations_.empty()) {
85-
Status lookup_error = Status{Error::kInvalidArgument,
85+
Status lookup_error = Status{Error::kErrorInvalidArgument,
8686
"Firestore transactions require all reads to "
8787
"be executed before all writes"};
8888
callback(lookup_error);
@@ -146,7 +146,7 @@ StatusOr<Precondition> Transaction::CreateUpdatePrecondition(
146146
//
147147
// Note: this can change once we can send separate verify writes in the
148148
// transaction.
149-
return Status{Error::kInvalidArgument,
149+
return Status{Error::kErrorInvalidArgument,
150150
"Can't update a document that doesn't exist."};
151151
}
152152
// Document exists, just base precondition on document update time.

Firestore/core/src/core/transaction_runner.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ bool IsRetryableTransactionError(const util::Status& error) {
3939
// FAILED_PRECONDITION and non-matching document versions with ABORTED. These
4040
// errors should be retried.
4141
Error code = error.code();
42-
return code == Error::kAborted || code == Error::kFailedPrecondition ||
42+
return code == Error::kErrorAborted ||
43+
code == Error::kErrorFailedPrecondition ||
4344
!remote::Datastore::IsPermanentError(error);
4445
}
4546
} // namespace

Firestore/core/src/local/leveldb_mutation_queue.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ Message<firestore_client_MutationQueue> LevelDbMutationQueue::MetadataForKey(
474474

475475
if (reader.ok()) {
476476
return result;
477-
} else if (reader.status().code() == Error::kNotFound) {
477+
} else if (reader.status().code() == Error::kErrorNotFound) {
478478
// Return a default-constructed message (`TryParse` is guaranteed to return
479479
// a default-constructed message on failure).
480480
return result;

0 commit comments

Comments
 (0)