recordError method
Future<void>
recordError(
- dynamic exception,
- StackTrace? stack, {
- dynamic reason,
- Iterable<
Object> information = const [], - bool? printDetails,
- bool fatal = false,
Submits a Crashlytics report of a caught error.
Implementation
Future<void> recordError(dynamic exception, StackTrace? stack,
{dynamic reason,
Iterable<Object> information = const [],
bool? printDetails,
bool fatal = false}) async {
// Use the debug flag if printDetails is not provided
printDetails ??= kDebugMode;
final String _information = information.isEmpty
? ''
: (StringBuffer()..writeAll(information, '\n')).toString();
if (printDetails) {
// ignore: avoid_print
print('----------------FIREBASE CRASHLYTICS----------------');
// If available, give a reason to the exception.
if (reason != null) {
// ignore: avoid_print
print('The following exception was thrown $reason:');
}
// Need to print the exception to explain why the exception was thrown.
// ignore: avoid_print
print(exception);
// Print information provided by the Flutter framework about the exception.
// ignore: avoid_print
if (_information.isNotEmpty) print('\n$_information');
// Not using Trace.format here to stick to the default stack trace format
// that Flutter developers are used to seeing.
// ignore: avoid_print
if (stack != null) print('\n$stack');
// ignore: avoid_print
print('----------------------------------------------------');
}
// Replace null or empty stack traces with the current stack trace.
final StackTrace stackTrace = (stack == null || stack.toString().isEmpty)
? StackTrace.current
: stack;
// Report error.
final List<Map<String, String>> stackTraceElements =
getStackTraceElements(stackTrace);
final String? buildId = getBuildId(stackTrace);
return _delegate.recordError(
exception: exception.toString(),
reason: reason?.toString(),
information: _information,
stackTraceElements: stackTraceElements,
buildId: buildId,
fatal: fatal,
);
}