Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to report a non-fatal exception with Firebase crash on iOS?

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"));
like image 770
zeus Avatar asked May 08 '17 16:05

zeus


People also ask

What is non-fatal error IOS?

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.

What is non-fatal exception in Firebase?

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.

How do I check my Firebase crash log?

Crashlytics associates the logs with your crash data and displays them in the Crashlytics page of the Firebase console, under the Logs tab.

What is Firebase crash?

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.


2 Answers

You can now log non-fatal exceptions in Firebase Crashlytics

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:

Example output showing non-fatal exceptions in Firebase Crashlytics console

Issue details page in the console (showing userInfo key-value pairs):

Example details view of a non-fatal exception issue in the Firebase Crashlytics console (showing userInfo key-value pairs)

like image 54
10623169 Avatar answered Nov 09 '22 21:11

10623169


Jen's answer is correct. There are a few alternatives you can consider, though:

  1. 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.

  2. 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.

  3. 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. :)

like image 29
Todd Kerpelman Avatar answered Nov 09 '22 20:11

Todd Kerpelman