When using Cloud Firestore in my Flutter application I want to use the error codes to return a localized error message to the user. However, I did not find a list of all the possible error codes that could occur. Is there a list like that or do I have to handle the errors differently?
You can see the list of possible exception codes at the gRPC or at the documentation. But, you need to change the code from uppercase to all lowercase and replace underscore with dash. For example:
PERMISSION_DENIED -> permission-denied
NOT_FOUND -> not-found
And so on.
Also, you need to catch FirebaseException instead of PlatformException in the new version of cloud_firestore.
Please have a look at the exception codes from the firebase firestore documentation.
Related
I'm trying to execute a query that has where and orderBy in a FirebaseFirestore.instance.collection('collectionName').where('fieldName1', isEqualTo: 'value1').orderBy('fieldName1', descending:true).snapshots() statement. I've also created a composite index for both fields defined in the above statement.
Though, I'm getting this error:
[log] [cloud_firestore/failed-precondition] Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console.
I'm using
firebase_core: ^1.3.0
cloud_firestore: ^2.3.0
I guess something might be wrong with the index. I recommend you to follow these steps:
Delete the index.
Run the function again. An error will be thrown.
Check the logs with adb logcat.
Some information will appear to create the appropriate index.
See the image
I used the firestore API to get data from FireBase. But encountered the error as above. I checked the read and write data on Cloud FireStore and found that read permission was allowed but I don't know why it still can't be done. Please help me. thank you so much.
This is my sample code:
See the image
first, you should use catch method, to avoid unhandled promise error. So
.then(() => {}).catch((error) => console.log(error))
second if you got permission error, then you should set your firestore rules correctly. If you are in development state then i suggest set values true like this:
allow read, write : true;
I'm trying to handle Firebase errors in Flutter using FlutterFire. Various functions throw FirebaseException, for example if calling an HttpsCallable when there is no internet connection. I need to figure out what to do depending on the error - for example, if there is no internet connection, show a message, else if it's an unknown error log an exception.
The exception has a code to achieve this:
/// The optional code to accommodate the message.
///
/// Allows users to identify the exception from a short code-name, for example
/// "no-app" is used when a user attempts to read a [FirebaseApp] which does
/// not exist.
final String code;
But I can't find anywhere where these codes are documented, which kind of makes them useless. I've searched for ages. Am I missing something? Does anyone have a link? How can I achieve this?
Auth error code firebase in code
Core dart code
For user in firebase in code
and so on... Could not find one place where everything is added...
Looking for some clarification as to how one can log caught exceptions using flutter's firebase_crashlytics package.
If I understand correctly (and from running some sample code) Crashlytics.instance.log('text'); will only add logs to the next crash report, rather than send off a non-fatal issue itself.
I'm looking for functionality which is equivalent to Crashlytics.logException(e); on Android, e.g.
try {
throwException();
} catch (e) {
Crashlytics.logException(e);
}
which allows you to log caught exceptions so they appear as non-fatal issues in the Crashlytics dashboard.
Is this currently possible with flutter's firebase_crashlytics package?
Is calling Crashlytics.instance.recordError('text', StackTrace.current) the way to achieve this for now?
Many thanks!
Short answer, yes.
Crashlytics.instance.recordError() is the equivalent of Crashlytics.logException()
If you dig into the Flutter firebase_crashlytics source code, you can actually see what Android APIs are involved.
Flutter’s recordError() invokes the method Crashlytics#onError in the Android library.
And tracing Crashlytics#onError, you’ll see that it goes to Crashlytics.logException(exception);
Additional note, you’ll also notice why Crashlytics.instance.log() ”will only add logs to the next crash report”. These logs are added to a ListQueue<String> _logs which is then packaged into the next call of recordError()
A snippet of Flutter’s invocation of Crashlytics.logException():
_recordError(...) {
...
final String result = await channel
.invokeMethod<String>('Crashlytics#onError', <String, dynamic>{
'exception': "${exception.toString()}",
'context': '$context',
'information': _information,
'stackTraceElements': stackTraceElements,
'logs': _logs.toList(),
'keys': _prepareKeys(),
});
}
And some reference notes for Crashlytics.logException():
To reduce your users’ network traffic, Crashlytics batches logged
exceptions together and sends them the next time the app launches.
For any individual app session, only the most recent 8 logged
exceptions are stored.
To add to the accepted answer, Crashlytics.instance.recordError() has now been deprecated for the new method FirebaseCrashlytics.instance.recordError(exception, stack).
BONUS TIP:
I had this problem where all the logged exceptions are grouped under the same issue in Crashlytics dashboard. These might be different crashes of the same or different code components. Due to this, I had to manually go through each instance of the crash to verify.
From my own testing, I found out the grouping is based on the top-most line in the stack trace you passed into the method above. Luckily, Dart has an easy way to get the current stack trace using StackTrace.current.
So to properly group the issues: get the current stack trace at the time of the exception and pass it in FirebaseCrashlytics.instance.recordError(exception, stack).
Hope this helps someone out there, I looked everywhere on the internet for a similar issue but can't find any.
I am implementing Firebase Auth into my Flutter app. How do I access error codes or user friendly error messages from Firebase? Is this available yet?
For example, on iOS you can get the localisedDescription from an error.
In Dart I have a onError: and catchError Futures which return an error object, but don't appear to have the relevant associated information.
it is available. the problem is that the catchError value is not an object, so you can't loop thru its keys. print/debugPrint just outputs the values without giving you any clue how to reference only one of them.
it has getter methods - code, message, and...details. 'details' is the human-readable result, but it's not documented on the firebase_auth flutter example. do this:
}).catchError((e) {
print(e.details); // code, message, details
});