@@ -2,6 +2,7 @@ import 'dart:async';
22import 'dart:io' ;
33import 'package:app/access/bugsee/bugsee_configuration_data.dart' ;
44import 'package:app/access/bugsee/bugsee_repository.dart' ;
5+ import 'package:app/access/persistence_exception.dart' ;
56import 'package:app/business/bugsee/bugsee_config_state.dart' ;
67import 'package:app/business/logger/logger_manager.dart' ;
78import 'package:bugsee_flutter/bugsee_flutter.dart' ;
@@ -16,22 +17,20 @@ const String bugseeFilterRegex = r'.';
1617
1718/// Service related to initializing Bugsee service
1819abstract interface class BugseeManager {
19- factory BugseeManager ({
20- required Logger logger,
21- required LoggerManager loggerManager,
22- required BugseeRepository bugseeRepository,
23- }) = _BugseeManager ;
20+ factory BugseeManager () = _BugseeManager ;
2421
2522 /// Current BugseeManager state
2623 BugseeConfigState get bugseeConfigState;
27- bool get onPressExceptionActivated;
2824
2925 /// Initialize bugsee with given token
3026 /// bugsee is not available in debug mode
3127 /// * [bugseeToken] : nullable bugsee token, if null bugsee won't be initialized make sure you provide
3228 /// [BUGSEE_TOKEN] in the env using `--dart-define` or `launch.json` on vscode
3329 Future <void > initialize ({
3430 String ? bugseeToken,
31+ required Logger logger,
32+ required LoggerManager loggerManager,
33+ required BugseeRepository bugseeRepository,
3534 });
3635
3736 /// Manually log a provided exception with a stack trace
@@ -47,14 +46,6 @@ abstract interface class BugseeManager {
4746 StackTrace ? stackTrace,
4847 Map <String , dynamic >? traces,
4948 Map <String , Map <String , dynamic >?>? events,
50- Map <String , dynamic >? attributes,
51- });
52-
53- /// Manually log an unhandled exception with a stack trace
54- /// (critical severity exception in Bugsee dashboard)
55- Future <void > logUnhandledException ({
56- required Exception exception,
57- StackTrace ? stackTrace,
5849 });
5950
6051 /// Manually update the current BugseeEnabled flag in shared prefs and in current manager singleton.
@@ -75,29 +66,26 @@ abstract interface class BugseeManager {
7566 /// Manually update isLogFilterEnabled flag in shared prefs.
7667 Future <void > setIsLogFilterEnabeld (bool value);
7768
78- /// Manually update whether bugsee will catch exception when pressing
79- /// dadjoke item or not.
80- ///
81- /// By is set to `false`
82- void setOnPressExceptionActivated (bool value);
83-
8469 /// Manually update whether Bugsee attach the log file with the reported
8570 /// exception or not.
8671 ///
8772 /// By default the log file is attached
8873 Future <void > setAttachLogFileEnabled (bool value);
74+
75+ //TODO add documentation
76+ Future <void > inteceptor (Object error, StackTrace stackTrace);
77+ Future <void > addAttributes (Map <String , dynamic > attributes);
78+ Future <void > addEmailAttribute (String email);
79+ Future <void > clearEmailAttribute ();
80+ Future <void > clearAttribute (String attribute);
8981}
9082
9183final class _BugseeManager implements BugseeManager {
92- final Logger logger;
93- final LoggerManager loggerManager;
94- final BugseeRepository bugseeRepository;
95-
96- _BugseeManager ({
97- required this .logger,
98- required this .loggerManager,
99- required this .bugseeRepository,
100- });
84+ late Logger logger;
85+ late LoggerManager loggerManager;
86+ late BugseeRepository bugseeRepository;
87+
88+ _BugseeManager ();
10189
10290 BugseeConfigState _currentState = const BugseeConfigState ();
10391
@@ -107,15 +95,19 @@ final class _BugseeManager implements BugseeManager {
10795 late bool _isBugSeeInitialized;
10896 late BugseeConfigurationData configurationData;
10997
110- @override
111- bool onPressExceptionActivated = false ;
112-
11398 BugseeLaunchOptions ? launchOptions;
11499
115100 @override
116101 Future <void > initialize ({
117102 String ? bugseeToken,
103+ required Logger logger,
104+ required LoggerManager loggerManager,
105+ required BugseeRepository bugseeRepository,
118106 }) async {
107+ this .logger = logger;
108+ this .loggerManager = loggerManager;
109+ this .bugseeRepository = bugseeRepository;
110+
119111 configurationData = await bugseeRepository.getBugseeConfiguration ();
120112 configurationData = configurationData.copyWith (
121113 isLogCollectionEnabled: configurationData.isLogCollectionEnabled ??
@@ -231,7 +223,6 @@ final class _BugseeManager implements BugseeManager {
231223 StackTrace ? stackTrace,
232224 Map <String , dynamic >? traces,
233225 Map <String , Map <String , dynamic >?>? events,
234- Map <String , dynamic >? attributes,
235226 }) async {
236227 if (_currentState.isBugseeEnabled) {
237228 if (traces != null ) {
@@ -246,26 +237,10 @@ final class _BugseeManager implements BugseeManager {
246237 }
247238 }
248239
249- if (attributes != null ) {
250- for (var attribute in attributes.entries) {
251- await Bugsee .setAttribute (attribute.key, attribute.value);
252- }
253- }
254-
255240 await Bugsee .logException (exception, stackTrace);
256241 }
257242 }
258243
259- @override
260- Future <void > logUnhandledException ({
261- required Exception exception,
262- StackTrace ? stackTrace,
263- }) async {
264- if (_currentState.isBugseeEnabled) {
265- await Bugsee .logUnhandledException (exception);
266- }
267- }
268-
269244 @override
270245 Future <void > setIsBugseeEnabled (bool value) async {
271246 if (_currentState.isConfigurationValid) {
@@ -345,11 +320,6 @@ final class _BugseeManager implements BugseeManager {
345320 }
346321 }
347322
348- @override
349- void setOnPressExceptionActivated (bool value) {
350- onPressExceptionActivated = value;
351- }
352-
353323 @override
354324 Future <void > setAttachLogFileEnabled (bool value) async {
355325 if (_currentState.isBugseeEnabled) {
@@ -360,4 +330,44 @@ final class _BugseeManager implements BugseeManager {
360330 );
361331 }
362332 }
333+
334+ @override
335+ Future <void > inteceptor (
336+ Object error,
337+ StackTrace stackTrace,
338+ ) async {
339+ String ? message = switch (error.runtimeType) {
340+ const (PersistenceException ) => (error as PersistenceException ).message,
341+ _ => null ,
342+ };
343+ await logException (
344+ exception: Exception (error),
345+ stackTrace: stackTrace,
346+ traces: {
347+ 'message' : message,
348+ },
349+ );
350+ }
351+
352+ @override
353+ Future <void > addAttributes (Map <String , dynamic > attributes) async {
354+ for (var attribute in attributes.entries) {
355+ await Bugsee .setAttribute (attribute.key, attribute.value);
356+ }
357+ }
358+
359+ @override
360+ Future <void > clearAttribute (String attribute) async {
361+ await Bugsee .clearAttribute (attribute);
362+ }
363+
364+ @override
365+ Future <void > addEmailAttribute (String email) async {
366+ await Bugsee .setEmail (email);
367+ }
368+
369+ @override
370+ Future <void > clearEmailAttribute () async {
371+ await Bugsee .clearEmail ();
372+ }
363373}
0 commit comments