From a7ddad3baff1ab262dc46a5280b74496ec1a619f Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 31 Jan 2019 11:26:59 +0200 Subject: [PATCH] Add sentry --- lib/.env.dart.example | 1 + lib/main.dart | 44 ++++++++++++++++++++++++++++++++++++++----- pubspec.lock | 14 ++++++++++++++ pubspec.yaml | 1 + 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/lib/.env.dart.example b/lib/.env.dart.example index 44689bfa6..941ed171f 100644 --- a/lib/.env.dart.example +++ b/lib/.env.dart.example @@ -4,4 +4,5 @@ class Config { static const String LOGIN_URL = 'http://www.ninja.test'; static const String LOGIN_SECRET = 'secret'; static const String API_SECRET = 'secret'; + static const String SENTRY_DNS = ''; } diff --git a/lib/main.dart b/lib/main.dart index 3a3bca8f4..b2ad379e5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,9 @@ +import 'dart:async'; + import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; +import 'package:invoiceninja_flutter/.env.dart'; +import 'package:sentry/sentry.dart'; import 'package:invoiceninja_flutter/redux/company/company_selectors.dart'; import 'package:invoiceninja_flutter/ui/app/app_builder.dart'; import 'package:invoiceninja_flutter/ui/invoice/invoice_email_vm.dart'; @@ -37,27 +41,24 @@ import 'package:invoiceninja_flutter/redux/invoice/invoice_middleware.dart'; import 'package:invoiceninja_flutter/ui/invoice/invoice_screen.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:local_auth/local_auth.dart'; -//import 'package:quick_actions/quick_actions.dart'; +//import 'package:quick_actions/quick_actions.dart'; // STARTER: import - do not remove comment import 'package:invoiceninja_flutter/ui/task/task_screen.dart'; import 'package:invoiceninja_flutter/ui/task/edit/task_edit_vm.dart'; import 'package:invoiceninja_flutter/ui/task/view/task_view_vm.dart'; import 'package:invoiceninja_flutter/redux/task/task_actions.dart'; import 'package:invoiceninja_flutter/redux/task/task_middleware.dart'; - import 'package:invoiceninja_flutter/ui/project/project_screen.dart'; import 'package:invoiceninja_flutter/ui/project/edit/project_edit_vm.dart'; import 'package:invoiceninja_flutter/ui/project/view/project_view_vm.dart'; import 'package:invoiceninja_flutter/redux/project/project_actions.dart'; import 'package:invoiceninja_flutter/redux/project/project_middleware.dart'; - import 'package:invoiceninja_flutter/ui/payment/payment_screen.dart'; import 'package:invoiceninja_flutter/ui/payment/edit/payment_edit_vm.dart'; import 'package:invoiceninja_flutter/ui/payment/view/payment_view_vm.dart'; import 'package:invoiceninja_flutter/redux/payment/payment_actions.dart'; import 'package:invoiceninja_flutter/redux/payment/payment_middleware.dart'; - import 'package:invoiceninja_flutter/ui/quote/quote_screen.dart'; import 'package:invoiceninja_flutter/ui/quote/edit/quote_edit_vm.dart'; import 'package:invoiceninja_flutter/ui/quote/view/quote_view_vm.dart'; @@ -65,10 +66,12 @@ import 'package:invoiceninja_flutter/redux/quote/quote_actions.dart'; import 'package:invoiceninja_flutter/redux/quote/quote_middleware.dart'; void main() async { + final SentryClient _sentry = SentryClient(dsn: Config.SENTRY_DNS); final prefs = await SharedPreferences.getInstance(); final enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode) ?? false; final requireAuthentication = prefs.getBool(kSharedPrefRequireAuthentication) ?? false; + final store = Store(appReducer, initialState: AppState( enableDarkMode: enableDarkMode, @@ -89,7 +92,38 @@ void main() async { LoggingMiddleware.printer(), ])); - runApp(InvoiceNinjaApp(store: store)); + Future _reportError(dynamic error, dynamic stackTrace) async { + print('Caught error: $error'); + if (isInDebugMode) { + print(stackTrace); + return; + } else { + _sentry.captureException( + exception: error, + stackTrace: stackTrace, + ); + } + } + + runZoned>(() async { + runApp(InvoiceNinjaApp(store: store)); + }, onError: (dynamic error, dynamic stackTrace) { + _reportError(error, stackTrace); + }); + + FlutterError.onError = (FlutterErrorDetails details) { + if (isInDebugMode) { + FlutterError.dumpErrorToConsole(details); + } else { + Zone.current.handleUncaughtError(details.exception, details.stack); + } + }; +} + +bool get isInDebugMode { + bool inDebugMode = false; + assert(inDebugMode = true); + return inDebugMode; } class InvoiceNinjaApp extends StatefulWidget { diff --git a/pubspec.lock b/pubspec.lock index 84c61e33e..55b5fb205 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -495,6 +495,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.3.0" + sentry: + dependency: "direct main" + description: + name: sentry + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" share: dependency: "direct main" description: @@ -654,6 +661,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.3" + usage: + dependency: transitive + description: + name: usage + url: "https://pub.dartlang.org" + source: hosted + version: "3.4.1" utf: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 26c90f855..d52f85be5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,7 @@ dependencies: google_sign_in: ^3.2.4 firebase_auth: ^0.6.2+1 local_auth: ^0.3.0 + sentry: ^2.2.0 #quick_actions: ^0.2.1 #flutter_html_view: ^0.5.8 #flutter_html: ^0.5.3