From 028b1e4ed8f4ab5644bdc6ea6feb1973088e4ac7 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 4 Oct 2020 11:52:06 +0200 Subject: [PATCH] hotfix: Capture Exception --- lib/components/matrix.dart | 22 ++++++++++++++-------- lib/main.dart | 26 ++++++++++++++------------ lib/utils/famedlysdk_store.dart | 2 -- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index cf25467..d4b51ce 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -15,6 +15,7 @@ import 'package:localstorage/localstorage.dart'; import 'package:universal_html/prefer_universal/html.dart' as html; import 'package:url_launcher/url_launcher.dart'; +import '../main.dart'; import '../utils/app_route.dart'; import '../utils/beautify_string_extension.dart'; import '../utils/famedlysdk_store.dart'; @@ -83,15 +84,20 @@ class MatrixState extends State { void _initWithStore() async { var initLoginState = client.onLoginStateChanged.stream.first; - client.database = await getDatabase(client); - client.connect(); - if (await initLoginState == LoginState.logged && PlatformInfos.isMobile) { - await FirebaseController.setupFirebase( - this, - widget.clientName, - ); + try { + client.database = await getDatabase(client); + client.connect(); + if (await initLoginState == LoginState.logged && PlatformInfos.isMobile) { + await FirebaseController.setupFirebase( + this, + widget.clientName, + ); + } + _cleanUpUserStatus(userStatuses); + } catch (e, s) { + client.onLoginStateChanged.sink.addError(e, s); + captureException(e, s); } - _cleanUpUserStatus(userStatuses); } Map getAuthByPassword(String password, [String session]) => { diff --git a/lib/main.dart b/lib/main.dart index 8a28a69..bdab3bb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,23 +18,25 @@ import 'views/chat_list.dart'; final sentry = SentryClient(dsn: '8591d0d863b646feb4f3dda7e5dcab38'); +void captureException(error, stackTrace) async { + final storage = LocalStorage('LocalStorage'); + await storage.ready; + debugPrint(error.toString()); + debugPrint(stackTrace.toString()); + if (storage.getItem('sentry') == true) { + await sentry.captureException( + exception: error, + stackTrace: stackTrace, + ); + } +} + void main() { SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle(statusBarColor: Colors.transparent)); runZonedGuarded( () => runApp(App()), - (error, stackTrace) async { - final storage = LocalStorage('LocalStorage'); - await storage.ready; - debugPrint(error.toString()); - debugPrint(stackTrace.toString()); - if (storage.getItem('sentry') == true) { - await sentry.captureException( - exception: error, - stackTrace: stackTrace, - ); - } - }, + captureException, ); } diff --git a/lib/utils/famedlysdk_store.dart b/lib/utils/famedlysdk_store.dart index 95386f3..5752ce7 100644 --- a/lib/utils/famedlysdk_store.dart +++ b/lib/utils/famedlysdk_store.dart @@ -36,8 +36,6 @@ Future getDatabase(Client client) async { await store.setItem('database-password', password); } return _db; - } catch (_) { - rethrow; } finally { _generateDatabaseLock = false; }