From d8b9cf18f0fef51bf76634ba27c20ac9d9cc229d Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Fri, 10 Jul 2020 08:37:38 +0200 Subject: [PATCH] sentry diagnostics --- lib/main.dart | 76 +++++++++- lib/widgets/bottom_nav.dart | 4 + pubspec.lock | 294 +++++++++++++++++++++++++++++++++++- pubspec.yaml | 6 +- 4 files changed, 374 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f7ebb67..f21b3ae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:aitrainer_app/view/account.dart'; import 'package:aitrainer_app/view/customer_bodytype_page.dart'; import 'package:aitrainer_app/view/customer_fitness_page.dart'; @@ -25,8 +27,73 @@ import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:aitrainer_app/localization/app_localization.dart'; +import 'package:sentry/sentry.dart'; -void main() { +final SentryClient _sentry = new SentryClient(dsn: 'https://5fac40cbfcfb4c15aa80c7a8638d7310@o418565.ingest.sentry.io/5322520'); + +/// Whether the VM is running in debug mode. +/// +/// This is useful to decide whether a report should be sent to sentry. Usually +/// reports from dev mode are not very useful, as these happen on developers' +/// workspaces rather than on users' devices in production. +bool get isInDebugMode { + bool inDebugMode = false; + assert(inDebugMode = true); + return inDebugMode; +} + +/// Reports [error] along with its [stackTrace] to Sentry.io. +Future _reportError(dynamic error, dynamic stackTrace) async { + print('Caught error: $error'); + + // Errors thrown in development mode are unlikely to be interesting. You can + // check if you are running in dev mode using an assertion and omit sending + // the report. + if (isInDebugMode) { + print(stackTrace); + print('In dev mode. Not sending report to Sentry.io.'); + return; + } + + print('Reporting to Sentry.io...'); + + final SentryResponse response = await _sentry.captureException( + exception: error, + stackTrace: stackTrace, + ); + + if (response.isSuccessful) { + print('Success! Event ID: ${response.eventId}'); + } else { + print('Failed to report to Sentry.io: ${response.error}'); + } +} + +Future main() async { + // This captures errors reported by the Flutter framework. + FlutterError.onError = (FlutterErrorDetails details) async { + if (isInDebugMode) { + // In development mode simply print to console. + FlutterError.dumpErrorToConsole(details); + } else { + // In production mode report to the application zone to report to + // Sentry. + Zone.current.handleUncaughtError(details.exception, details.stack); + } + }; + + // This creates a [Zone] that contains the Flutter application and stablishes + // an error handler that captures errors and reports them. + // + // Using a zone makes sure that as many errors as possible are captured, + // including those thrown from [Timer]s, microtasks, I/O, and those forwarded + // from the `FlutterError` handler. + // + // More about zones: + // + // - https://api.dartlang.org/stable/1.24.2/dart-async/Zone-class.html + // - https://www.dartlang.org/articles/libraries/zones + runZonedGuarded>(() async { runApp( MultiProvider( // Initialize the model in the builder. That way, Provider @@ -38,10 +105,13 @@ void main() { ], child: AitrainerApp(), - ), - ); + )); + }, (error, stackTrace) async { + await _reportError(error, stackTrace); + }); } + class AitrainerApp extends StatelessWidget { @override diff --git a/lib/widgets/bottom_nav.dart b/lib/widgets/bottom_nav.dart index 538b872..7008318 100644 --- a/lib/widgets/bottom_nav.dart +++ b/lib/widgets/bottom_nav.dart @@ -40,6 +40,10 @@ class BottomNavigator { Navigator.of(context).pop(); Navigator.of(context).pushNamed('home'); + break; + case 1: + throw new StateError('This is a Dart exception on event.'); + break; case 2: Navigator.of(context).pop(); diff --git a/pubspec.lock b/pubspec.lock index 60ef7bc..ed1bbf3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "0.39.12" archive: dependency: transitive description: @@ -57,13 +71,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + coverage: + dependency: transitive + description: + name: coverage + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.11" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "2.1.4" + csslib: + dependency: transitive + description: + name: csslib + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" cupertino_icons: dependency: "direct main" description: @@ -92,6 +120,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.0" flutter: dependency: "direct main" description: flutter @@ -104,6 +139,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.8" + flutter_driver: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" flutter_launcher_icons: dependency: "direct dev" description: @@ -117,10 +157,29 @@ packages: source: sdk version: "0.0.0" flutter_test: - dependency: "direct dev" + dependency: transitive description: flutter source: sdk version: "0.0.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + html: + dependency: transitive + description: + name: html + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.0+3" http: dependency: "direct dev" description: @@ -128,6 +187,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" http_parser: dependency: transitive description: @@ -149,6 +215,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.16.1" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.4" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.2" + json_rpc_2: + dependency: transitive + description: + name: json_rpc_2 + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "0.11.4" matcher: dependency: transitive description: @@ -163,6 +257,55 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.8" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.6+3" + mockito: + dependency: "direct main" + description: + name: mockito + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.1" + multi_server_socket: + dependency: transitive + description: + name: multi_server_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + node_interop: + dependency: transitive + description: + name: node_interop + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + node_io: + dependency: transitive + description: + name: node_io + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + node_preamble: + dependency: transitive + description: + name: node_preamble + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.12" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.3" path: dependency: transitive description: @@ -184,6 +327,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.4" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.0" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.12" provider: dependency: "direct dev" description: @@ -191,6 +355,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.2.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.4" + sentry: + dependency: "direct main" + description: + name: sentry + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" shared_preferences: dependency: "direct dev" description: @@ -198,11 +376,53 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.3" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.7" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shelf_static: + dependency: transitive + description: + name: shelf_static + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.8" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.3" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + source_maps: + dependency: transitive + description: + name: source_maps + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.9" source_span: dependency: transitive description: @@ -231,6 +451,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.5" + sync_http: + dependency: transitive + description: + name: sync_http + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" term_glyph: dependency: transitive description: @@ -238,6 +465,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + test: + dependency: "direct dev" + description: + name: test + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.4" test_api: dependency: transitive description: @@ -245,6 +479,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.15" + test_core: + dependency: transitive + description: + name: test_core + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.4" typed_data: dependency: transitive description: @@ -252,6 +493,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" + usage: + dependency: transitive + description: + name: usage + url: "https://pub.dartlang.org" + source: hosted + version: "3.4.2" vector_math: dependency: transitive description: @@ -259,6 +507,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + vm_service: + dependency: transitive + description: + name: vm_service + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.0" + vm_service_client: + dependency: transitive + description: + name: vm_service_client + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.6+2" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7+15" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + webdriver: + dependency: transitive + description: + name: webdriver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.3" xml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index de00cca..73fc99a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,13 +28,17 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.3 devicelocale: ^0.3.1 + sentry: ^3.0.1 + + mockito: ^4.1.1 flutter_localizations: sdk: flutter dev_dependencies: - flutter_test: + flutter_driver: sdk: flutter + test: any http: 0.12.1 provider: ^3.2.0