Skip to content

Commit 0f27491

Browse files
committed
chore: add flutter framework rendering error interceptor handler
1 parent 12f2d65 commit 0f27491

4 files changed

Lines changed: 34 additions & 58 deletions

File tree

src/app/lib/access/bugsee/bugsee_configuration_data.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class BugseeConfigurationData extends Equatable {
1616
/// Indicate whether logs are filtred during reports or not.
1717
final bool? isLogsFilterEnabled;
1818

19+
/// Indicate whether attaching file in the Bugsee report is enabled or not
1920
final bool? attachLogFileEnabled;
2021

2122
const BugseeConfigurationData({

src/app/lib/access/bugsee/bugsee_default_configuration.dart

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/app/lib/business/bugsee/bugsee_manager.dart

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ abstract interface class BugseeManager {
4040
///* stackTrace: the strack trace of the exception, by default it's null
4141
///* traces: the traces that led to the exception.
4242
///* events: the events where the exception has been caught.
43-
///* attributes: data related to the exception.
4443
Future<void> logException({
4544
required Exception exception,
4645
StackTrace? stackTrace,
@@ -72,11 +71,30 @@ abstract interface class BugseeManager {
7271
/// By default the log file is attached
7372
Future<void> setAttachLogFileEnabled(bool value);
7473

75-
//TODO add documentation
76-
Future<void> inteceptor(Object error, StackTrace stackTrace);
74+
/// Intecept all unhandled exception thrown by the dart framework
75+
Future<void> inteceptExceptions(Object error, StackTrace stackTrace);
76+
77+
/// Intercept all unhandled rending exception thrown by the Flutter framework
78+
Future<void> inteceptRenderExceptions(FlutterErrorDetails error);
79+
80+
/// Manually add a map of attributes
81+
/// - the map entry key is the attribute name
82+
/// - the map entry value is the attribute value (string, int, boolean)
83+
///
84+
/// Attributes will be attached to all reported exception unless app is uninstalled
85+
/// or attributes are removed manually
7786
Future<void> addAttributes(Map<String, dynamic> attributes);
87+
88+
/// Manually add an email attached to all reported.
89+
///
90+
/// The email will be attached to all reported exception unless app is uninstalled
91+
/// or the email is removed manually.
7892
Future<void> addEmailAttribute(String email);
93+
94+
/// Manually remove the email attribute attached using [addEmailAttribute]
7995
Future<void> clearEmailAttribute();
96+
97+
/// Manually remove an attribute by the given key attached using [addAttributes]
8098
Future<void> clearAttribute(String attribute);
8199
}
82100

@@ -332,7 +350,7 @@ final class _BugseeManager implements BugseeManager {
332350
}
333351

334352
@override
335-
Future<void> inteceptor(
353+
Future<void> inteceptExceptions(
336354
Object error,
337355
StackTrace stackTrace,
338356
) async {
@@ -370,4 +388,12 @@ final class _BugseeManager implements BugseeManager {
370388
Future<void> clearEmailAttribute() async {
371389
await Bugsee.clearEmail();
372390
}
391+
392+
@override
393+
Future<void> inteceptRenderExceptions(FlutterErrorDetails error) async {
394+
await logException(
395+
exception: Exception(error.exception),
396+
stackTrace: error.stack,
397+
);
398+
}
373399
}

src/app/lib/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ Future<void> main() async {
4040
_initializeBugseeManager();
4141
runZonedGuarded(
4242
() async {
43+
FlutterError.onError =
44+
GetIt.I.get<BugseeManager>().inteceptRenderExceptions;
4345
await initializeComponents();
4446
runApp(const App());
4547
},
46-
GetIt.I.get<BugseeManager>().inteceptor,
48+
GetIt.I.get<BugseeManager>().inteceptExceptions,
4749
);
4850
}
4951

0 commit comments

Comments
 (0)