Skip to content

Commit

Permalink
Add additional error handlers
Browse files Browse the repository at this point in the history
Should fix #11
  • Loading branch information
ThexXTURBOXx committed Oct 26, 2023
1 parent a6968ff commit 621170b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/core/catcher_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,17 @@ class Catcher2 implements ReportModeAction {
}

Future _setupErrorHooks() async {
FlutterError.onError = (details) async {
await _reportError(
FlutterError.onError = (details) {
_reportError(
details.exception,
details.stack,
errorDetails: details,
);
_currentConfig.onFlutterError?.call(details);
};
PlatformDispatcher.instance.onError = (error, stack) {
_reportError(error, stack);
_currentConfig.onPlatformError?.call(error, stack);
return true;
};

Expand Down
19 changes: 19 additions & 0 deletions lib/model/catcher_2_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:catcher_2/model/report.dart';
import 'package:catcher_2/model/report_handler.dart';
import 'package:catcher_2/model/report_mode.dart';
import 'package:catcher_2/utils/catcher_2_logger.dart';
import 'package:flutter/foundation.dart';

class Catcher2Options {
/// Handlers that should be used
Expand Down Expand Up @@ -51,6 +52,16 @@ class Catcher2Options {
/// milliseconds.
final int reportOccurrenceTimeout;

/// Function which should additionally be called when an error is caught using
/// the [FlutterError.onError] mechanism. Useful if other packages also need
/// to override this behaviour (such as integration tests).
final void Function(FlutterErrorDetails details)? onFlutterError;

/// Function which should additionally be called when an error is caught using
/// the [PlatformDispatcher.instance.onError] mechanism. Useful if other
/// packages also need to override this behaviour.
final void Function(Object error, StackTrace stack)? onPlatformError;

/// Logger instance.
final Catcher2Logger? logger;

Expand All @@ -68,6 +79,8 @@ class Catcher2Options {
this.excludedParameters = const [],
this.filterFunction,
this.reportOccurrenceTimeout = 3000,
this.onFlutterError,
this.onPlatformError,
this.logger,
});

Expand All @@ -85,6 +98,8 @@ class Catcher2Options {
excludedParameters = const [],
filterFunction = null,
reportOccurrenceTimeout = 3000,
onFlutterError = null,
onPlatformError = null,
logger = Catcher2Logger();

/// Builds default catcher 2 options debug instance
Expand All @@ -101,6 +116,8 @@ class Catcher2Options {
excludedParameters = const [],
filterFunction = null,
reportOccurrenceTimeout = 3000,
onFlutterError = null,
onPlatformError = null,
logger = Catcher2Logger();

/// Builds default catcher 2 options profile instance
Expand All @@ -117,5 +134,7 @@ class Catcher2Options {
excludedParameters = const [],
filterFunction = null,
reportOccurrenceTimeout = 3000,
onFlutterError = null,
onPlatformError = null,
logger = Catcher2Logger();
}

0 comments on commit 621170b

Please sign in to comment.