How to report on iOS a non-fatal exception using Firebase Crash Reporting? In Android, we can do something like this:
FirebaseCrash.report(new Exception("My first Firebase non-fatal error on Android"));
A non-fatal error is a failure in your application that didn't result in a crash for the user. In other words: the loss is recoverable, and the application can continue.
Non-Fatal logging is where we start using the advanced features of Crashlytics which helps in diagnosing and fixing issues beyond the crashes logged while the app was being used. When exceptions are logged manually in Firebase, they are logged as non-fatals.
Crashlytics associates the logs with your crash data and displays them in the Crashlytics page of the Firebase console, under the Logs tab.
Firebase Crashlytics is a lightweight, realtime crash reporter that helps you track, prioritize, and fix stability issues that erode your app quality. Crashlytics saves you troubleshooting time by intelligently grouping crashes and highlighting the circumstances that lead up to them.
The accepted answer is therefore no longer correct. Non-fatal exceptions can be logged with the following Firebase Crashlytics method:
Crashlytics.crashlytics().record(error: error)
From the documentation:
This allows you to record a non-fatal event, described by an NSError object. These events will be grouped and displayed similarly to crashes. Keep in mind that this method can be expensive. Also, the total number of NSErrors that can be recorded during your app's life-cycle is limited by a fixed-size circular buffer. If the buffer is overrun, the oldest data is dropped. Errors are relayed to Crashlytics on a subsequent launch of your application.
Example usage:
let userInfo: [String: String] = [
"deviceId": "someDeviceId",
"localizedDescription": yourException.localizedDescription,
"anotherKey": "anotherValue"
]
let domain = "METHOD: some/domain/that/just/had-an-exception"
let code = 404
let error = NSError(domain: domain, code: code, userInfo: userInfo)
Crashlytics.crashlytics().record(error: error)
Where domain
is some pretty identifier for use in Firebase (e.g. method + request path), code
is the status code of the exception (a 404 here), and userInfo
additional data are converted to key-value pairs and displayed in the keys/logs section within an individual issue.
Note: Logged errors are grouped by the NSError domain
and code
(unlike fatals, which are grouped in Firebase by their stack trace).
Example output in Firebase Console > Crashlytics
:
Issue details page in the console (showing userInfo
key-value pairs):
Jen's answer is correct. There are a few alternatives you can consider, though:
Log a Firebase Analytics event. While this won't give you all the stack tracey goodness you get from Firebase Crash Reporting, you can at least keep track of how often a particular exception is happening over time.
Use the FIRCrashMessage()
method to make note of any errors that occur in your app. You will only see these log methods in crash reports that end up getting reported to Firebase Crash Reporting, but given that errors often lead to crashes, this isn't such a bad idea.
Try Crashlytics. They have a reportError()
method that's specifically designed for reporting non-fatal errors. It's fine to use Crashlytics for your crash reporting while continuing to use other features of Firebase within your app -- it's all the same parent company these days. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With