FirestoreErrorCode enum

The status code of a FirestoreException. The codes and their numeric values are the canonical gRPC status codes.

Most codes come from the backend and reach you unchanged. The client also produces some of them itself; the documentation of each code says when, and whether trying the same operation again can help.

The client already retries, with a backoff, what a retry can fix: listens and writes that fail with cancelled, unknown, deadlineExceeded, resourceExhausted, internal, unavailable or unauthenticated are sent again without an error reaching you (writes also on aborted), and transactions are attempted again as described on FirebaseFirestore.runTransaction. An error you receive is usually one the client gave up on, or one from a call that does not retry by itself, such as a get with Source.server or an aggregation.

try {
  await firestore.doc('cities/SF').update(<String, Object?>{'visits': 1});
} on FirestoreException catch (e) {
  if (e.errorCode == FirestoreErrorCode.notFound) {
    print('No such city');
  } else if (e.errorCode == FirestoreErrorCode.permissionDenied) {
    print('Not allowed: ${e.message}');
  } else {
    rethrow;
  }
}

The names follow the Android SDK in lowerCamelCase; code is the string of FlutterFire and the JS SDK, for example 'permission-denied'.

New values may be added in any minor release: a switch over this enum needs a default (or wildcard) branch.

Inheritance
Available extensions

Values

ok → const FirestoreErrorCode

The operation completed successfully. Never the code of a thrown FirestoreException.

const FirestoreErrorCode(0, 'ok')
cancelled → const FirestoreErrorCode

The operation was cancelled, typically by the caller.

The client produces it when the signed-in user changes while a FirebaseFirestore.waitForPendingWrites future is waiting; the transport reports it for a call that was cancelled on the way. Retrying makes sense; for waitForPendingWrites, call it again for the new user.

const FirestoreErrorCode(1, 'cancelled')
unknown → const FirestoreErrorCode

An unknown error, or an error from a different error domain.

The client produces it when an error that is not a FirestoreException occurs below a write of a DocumentReference or in a call to the backend, and when FirebaseFirestore.clearPersistence cannot delete the files of the cache (on Windows, for example, while another isolate or process has them open). The message holds the original error. A retry can help if the cause was temporary.

const FirestoreErrorCode(2, 'unknown')
invalidArgument → const FirestoreErrorCode

The client passed an invalid argument. Unlike failedPrecondition, the argument is wrong regardless of the state of the system (for example a malformed field name).

The backend returns it for a request it cannot accept, for example a document or a value that exceeds a limit. The client produces it in a transaction that reads after writing, that updates a document it read as missing, that writes in a read-only transaction, or that calls Transaction.getQuery or Transaction.getAggregate in a read-write transaction; for a bundle that cannot be loaded; and for snapshot JSON that DocumentSnapshot.fromJson, QuerySnapshot.fromJson and the ...SnapshotsFromJson methods cannot read. Arguments that are wrong before anything is sent (invalid data, field paths or query combinations) are reported as an ArgumentError instead. Retrying the same call does not help; fix the call.

const FirestoreErrorCode(3, 'invalid-argument')
deadlineExceeded → const FirestoreErrorCode

The deadline expired before the operation could complete. The operation may still have succeeded on the server.

Comes from the backend or the transport, never from the client itself. A retry makes sense, but a write may then be applied twice: make it idempotent or read before writing again.

const FirestoreErrorCode(4, 'deadline-exceeded')
notFound → const FirestoreErrorCode

A requested document was not found.

The backend returns it for an update of a document that does not exist, in a single write, a batch or a transaction. A plain read of a missing document is not an error: its snapshot has exists false. Retrying does not help until the document exists; use set with a merge option to create or update it in one call.

const FirestoreErrorCode(5, 'not-found')
alreadyExists → const FirestoreErrorCode

The document the operation tried to create already exists.

The backend returns it when a write requires the document to be missing, for example in a transaction that read a document as missing and then wrote it while another client created it. Transactions retry on this code by themselves; elsewhere a retry of the same write fails again.

const FirestoreErrorCode(6, 'already-exists')
permissionDenied → const FirestoreErrorCode

The caller does not have permission to run the operation, for example because the security rules reject it.

The backend returns it. A rejected write is removed from the local cache again, and a rejected listen ends its stream with this error. Retrying does not help until the rules, the signed-in user or the data change.

const FirestoreErrorCode(7, 'permission-denied')
resourceExhausted → const FirestoreErrorCode

A resource has been exhausted, such as a per-user quota or the storage of the project.

The backend returns it. Retry later with a backoff; the client does so itself for listens and writes.

const FirestoreErrorCode(8, 'resource-exhausted')
failedPrecondition → const FirestoreErrorCode

The operation was rejected because the system is not in the state it requires, for example a query that needs an index that does not exist.

The backend returns it for a query that needs a composite index (the message has a link that creates it), and a transaction fails with it when the documents it read kept changing until its attempts were used up.

The client produces it for any call on a terminated FirebaseFirestore instance; for FirebaseFirestore.clearPersistence while the instance (or another one on the same cache) is running; for toJson of a snapshot with pending writes; and with a persistent cache, when the cache was opened by another version of the SDK or cleared by another client, when a client that shares the cache lost its primary role, or on the web when another tab already has the cache open. Retrying the same call does not help: change the state first (create a new instance, create the index, wait for the pending writes).

const FirestoreErrorCode(9, 'failed-precondition')
aborted → const FirestoreErrorCode

The operation was aborted, typically because of a concurrency problem such as a transaction conflict.

The backend returns it for a transaction that conflicts with another one; the client produces it when a transaction reads the same document twice and gets two versions. Transactions and writes retry on this code by themselves, so you see it only when the attempts were used up. A retry of the whole transaction can then succeed.

const FirestoreErrorCode(10, 'aborted')
outOfRange → const FirestoreErrorCode

The operation was attempted past the valid range.

Comes from the backend only. Retrying the same call does not help.

const FirestoreErrorCode(11, 'out-of-range')
unimplemented → const FirestoreErrorCode

The operation is not implemented or not supported.

The backend (or the emulator) returns it for a feature it does not support, for example one that needs the Enterprise edition. The client produces it when the backend answers an aggregation (also one in a transaction) without any response. Retrying does not help.

const FirestoreErrorCode(12, 'unimplemented')
internal → const FirestoreErrorCode

An internal error: an invariant expected by the underlying system was broken.

Comes from the backend. The client retries listens and writes; for other calls a retry with a backoff can help.

const FirestoreErrorCode(13, 'internal')
unavailable → const FirestoreErrorCode

The service is currently unavailable. This is most likely transient and the operation can be retried with a backoff.

The backend or the transport returns it when the server cannot be reached. The client produces it when a call needs the server while the client is offline: a get with Source.server, aggregations, vector queries and pipelines; for a get with Source.cache of a document that is not in the cache; and when the local cache cannot store a write or start a listen (for example a database that stays busy). Retry with a backoff, or read from the cache instead.

const FirestoreErrorCode(14, 'unavailable')
dataLoss → const FirestoreErrorCode

Unrecoverable data loss or corruption.

Comes from the backend only. Retrying does not help.

const FirestoreErrorCode(15, 'data-loss')
unauthenticated → const FirestoreErrorCode

The request does not carry valid authentication credentials for the operation.

The backend returns it for a missing, expired or invalid token. The client asks the token provider for a fresh token and retries listens and writes by itself. If you still see it, check how the app signs in (see package:firebase_auth_providers_dart).

const FirestoreErrorCode(16, 'unauthenticated')

Properties

code → String
The code in the form of FlutterFire and the JS SDK, for example 'permission-denied': the FirebaseException.code of a FirestoreException with this code.
final
hashCode → int
The hash code for this object.
no setterinherited
index → int
A numeric identifier for the enumerated value.
no setterinherited
name → String

Available on Enum, provided by the EnumName extension

The name of the enum value.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → int
The numeric gRPC status code, for example 7 for permissionDenied. values is in the order of these numbers.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

fromCode(String code) → FirestoreErrorCode
The code with the string code (for example 'permission-denied'), or unknown for a string that is no Firestore code.

Constants

values → const List<FirestoreErrorCode>
A constant List of the values in this enum, in order of their declaration.