Skip to content

Commit eac7894

Browse files
dotdoomkroikie
authored andcommitted
[firebase_crashlytics] Always log crash details in debug mode (#105)
* Always log crash details in debug mode And for Flutter error, always do it -- with FlutterError.dumpErrorToConsole, keeping existing Flutter behavior. * forceReport=true to dump every single FlutterError This preserves the previous behavior of logging details of every error caught by firebase_crashlytics plugin.
1 parent 14c97ac commit eac7894

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

packages/firebase_crashlytics/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.1
2+
3+
* Log FlutterErrorDetails using Flutter's standard `FlutterError.dumpErrorToConsole`.
4+
* In debug mode, always log errors.
5+
16
## 0.1.0+5
27

38
* Fix example app `support-compat` crash by setting `compileSdkVersion` to 28.

packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ class Crashlytics {
2828
/// to Firebase Crashlytics.
2929
Future<void> recordFlutterError(FlutterErrorDetails details) async {
3030
print('Flutter error caught by Crashlytics plugin:');
31+
// Since multiple errors can be caught during a single session, we set
32+
// forceReport=true.
33+
FlutterError.dumpErrorToConsole(details, forceReport: true);
3134

3235
_recordError(details.exceptionAsString(), details.stack,
3336
context: details.context,
3437
information: details.informationCollector == null
3538
? null
36-
: details.informationCollector());
39+
: details.informationCollector(),
40+
printDetails: false);
3741
}
3842

3943
/// Submits a report of a non-fatal error.
@@ -200,18 +204,25 @@ class Crashlytics {
200204
// occurred and give useful background information in [FlutterErrorDetails.informationCollector].
201205
// Crashlytics will log this information in addition to the stack trace.
202206
// If [information] is `null` or empty, it will be ignored.
203-
Future<void> _recordError(dynamic exception, StackTrace stack,
204-
{dynamic context, Iterable<DiagnosticsNode> information}) async {
207+
Future<void> _recordError(
208+
dynamic exception,
209+
StackTrace stack, {
210+
dynamic context,
211+
Iterable<DiagnosticsNode> information,
212+
bool printDetails,
213+
}) async {
205214
bool inDebugMode = false;
206215
if (!enableInDevMode) {
207216
assert(inDebugMode = true);
208217
}
209218

219+
printDetails ??= inDebugMode;
220+
210221
final String _information = (information == null || information.isEmpty)
211222
? ''
212223
: (StringBuffer()..writeAll(information, '\n')).toString();
213224

214-
if (inDebugMode && !enableInDevMode) {
225+
if (printDetails) {
215226
// If available, give context to the exception.
216227
if (context != null)
217228
print('The following exception was thrown $context:');
@@ -225,7 +236,8 @@ class Crashlytics {
225236
// Not using Trace.format here to stick to the default stack trace format
226237
// that Flutter developers are used to seeing.
227238
if (stack != null) print('\n$stack');
228-
} else {
239+
}
240+
if (!inDebugMode || enableInDevMode) {
229241
// The stack trace can be null. To avoid the following exception:
230242
// Invalid argument(s): Cannot create a Trace from null.
231243
// To avoid that exception, we can check for null and provide an empty stack trace.

packages/firebase_crashlytics/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: firebase_crashlytics
22
description:
33
Flutter plugin for Firebase Crashlytics. It reports uncaught errors to the
44
Firebase console.
5-
version: 0.1.0+5
5+
version: 0.1.1
66
author: Flutter Team <[email protected]>
77
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_crashlytics
88

0 commit comments

Comments
 (0)