From 4e405419c8bd75aeb264e6914282a80c24c0c417 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 25 Nov 2022 14:24:35 +0100 Subject: [PATCH 1/3] Capture Future errors for Flutter Web automatically --- CHANGELOG.md | 6 ++++++ .../lib/src/integrations/flutter_error_integration.dart | 5 ----- flutter/lib/src/sentry_flutter.dart | 8 +++++++- .../test/integrations/flutter_error_integration_test.dart | 4 ---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 875b1a4d0..2f580eeb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Capture Future errors for Flutter Web automatically ([#1143](https://github.com/getsentry/sentry-dart/pull/1143)) + ## 6.16.1 ### Fixes diff --git a/flutter/lib/src/integrations/flutter_error_integration.dart b/flutter/lib/src/integrations/flutter_error_integration.dart index b4b3d5892..062dcc9de 100644 --- a/flutter/lib/src/integrations/flutter_error_integration.dart +++ b/flutter/lib/src/integrations/flutter_error_integration.dart @@ -60,11 +60,6 @@ class FlutterErrorIntegration extends Integration { final mechanism = Mechanism( type: 'FlutterError', handled: true, - data: { - if (flutterErrorDetails.isNotEmpty) - 'hint': - 'See "flutter_error_details" down below for more information' - }, ); final throwableMechanism = ThrowableMechanism(mechanism, exception); diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 73067cc0e..4bb94160c 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -52,7 +52,13 @@ mixin SentryFlutter { final platformDispatcher = PlatformDispatcher.instance; final wrapper = PlatformDispatcherWrapper(platformDispatcher); - final isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions); + + // Flutter Web don't capture [Future] errors if using [PlatformDispatcher.onError] and not + // the [runZonedGuarded]. + // likely due to https://github.com/flutter/flutter/issues/100277 + final isOnErrorSupported = flutterOptions.platformChecker.isWeb + ? false + : wrapper.isOnErrorSupported(flutterOptions); // first step is to install the native integration and set default values, // so we are able to capture future errors. diff --git a/flutter/test/integrations/flutter_error_integration_test.dart b/flutter/test/integrations/flutter_error_integration_test.dart index 4fd2cee32..856f931a7 100644 --- a/flutter/test/integrations/flutter_error_integration_test.dart +++ b/flutter/test/integrations/flutter_error_integration_test.dart @@ -56,8 +56,6 @@ void main() { final throwableMechanism = event.throwableMechanism as ThrowableMechanism; expect(throwableMechanism.mechanism.type, 'FlutterError'); expect(throwableMechanism.mechanism.handled, true); - expect(throwableMechanism.mechanism.data['hint'], - 'See "flutter_error_details" down below for more information'); expect(throwableMechanism.throwable, exception); expect(event.contexts['flutter_error_details']['library'], 'sentry'); @@ -92,8 +90,6 @@ void main() { final throwableMechanism = event.throwableMechanism as ThrowableMechanism; expect(throwableMechanism.mechanism.type, 'FlutterError'); expect(throwableMechanism.mechanism.handled, true); - expect(throwableMechanism.mechanism.data['hint'], - 'See "flutter_error_details" down below for more information'); expect(event.contexts['flutter_error_details']['library'], 'sentry'); expect(event.contexts['flutter_error_details']['context'], From 54e8f958b5b6700e185c8f5ca282fe22a2986863 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 25 Nov 2022 14:25:02 +0100 Subject: [PATCH 2/3] fix pr id --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f580eeb6..6cda8ae28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- Capture Future errors for Flutter Web automatically ([#1143](https://github.com/getsentry/sentry-dart/pull/1143)) +- Capture Future errors for Flutter Web automatically ([#1152](https://github.com/getsentry/sentry-dart/pull/1152)) ## 6.16.1 From d8aa54afc3ac2ac29720db0a9583862e3fc1dbd4 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 25 Nov 2022 14:53:47 +0100 Subject: [PATCH 3/3] fix --- flutter/test/sentry_flutter_test.dart | 48 ++++++++++++++++++--------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index 7315d8aa6..4f3996bce 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: invalid_use_of_internal_member + import 'package:flutter_test/flutter_test.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; @@ -13,12 +15,15 @@ import 'sentry_flutter_util.dart'; /// They don't depend on the underlying platform. final platformAgnosticIntegrations = [ WidgetsFlutterBindingIntegration, - OnErrorIntegration, FlutterErrorIntegration, LoadReleaseIntegration, DebugPrintIntegration, ]; +final nonWebIntegrations = [ + OnErrorIntegration, +]; + // These should only be added to Android final androidIntegrations = [ LoadImageListIntegration, @@ -69,6 +74,7 @@ void main() { ...androidIntegrations, ...nativeIntegrations, ...platformAgnosticIntegrations, + ...nonWebIntegrations, ], shouldNotHaveIntegrations: iOsAndMacOsIntegrations); @@ -109,6 +115,7 @@ void main() { ...iOsAndMacOsIntegrations, ...nativeIntegrations, ...platformAgnosticIntegrations, + ...nonWebIntegrations, ], shouldNotHaveIntegrations: androidIntegrations, ); @@ -147,6 +154,7 @@ void main() { ...iOsAndMacOsIntegrations, ...nativeIntegrations, ...platformAgnosticIntegrations, + ...nonWebIntegrations, ], shouldNotHaveIntegrations: androidIntegrations, ); @@ -181,7 +189,10 @@ void main() { testConfiguration( integrations: integrations, - shouldHaveIntegrations: platformAgnosticIntegrations, + shouldHaveIntegrations: [ + ...platformAgnosticIntegrations, + ...nonWebIntegrations, + ], shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, @@ -219,7 +230,10 @@ void main() { testConfiguration( integrations: integrations, - shouldHaveIntegrations: platformAgnosticIntegrations, + shouldHaveIntegrations: [ + ...platformAgnosticIntegrations, + ...nonWebIntegrations, + ], shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, @@ -265,13 +279,14 @@ void main() { ...androidIntegrations, ...iOsAndMacOsIntegrations, ...nativeIntegrations, + ...nonWebIntegrations, ], ); testBefore( - integrations: integrations, - beforeIntegration: WidgetsFlutterBindingIntegration, - afterIntegration: OnErrorIntegration); + integrations: Sentry.currentHub.options.integrations, + beforeIntegration: RunZonedGuardedIntegration, + afterIntegration: WidgetsFlutterBindingIntegration); await Sentry.close(); }); @@ -308,13 +323,14 @@ void main() { ...androidIntegrations, ...iOsAndMacOsIntegrations, ...nativeIntegrations, + ...nonWebIntegrations, ], ); testBefore( - integrations: integrations, - beforeIntegration: WidgetsFlutterBindingIntegration, - afterIntegration: OnErrorIntegration); + integrations: Sentry.currentHub.options.integrations, + beforeIntegration: RunZonedGuardedIntegration, + afterIntegration: WidgetsFlutterBindingIntegration); await Sentry.close(); }); @@ -351,13 +367,14 @@ void main() { ...androidIntegrations, ...iOsAndMacOsIntegrations, ...nativeIntegrations, + ...nonWebIntegrations, ], ); testBefore( - integrations: integrations, - beforeIntegration: WidgetsFlutterBindingIntegration, - afterIntegration: OnErrorIntegration); + integrations: Sentry.currentHub.options.integrations, + beforeIntegration: RunZonedGuardedIntegration, + afterIntegration: WidgetsFlutterBindingIntegration); await Sentry.close(); }); @@ -393,13 +410,14 @@ void main() { ...androidIntegrations, ...iOsAndMacOsIntegrations, ...nativeIntegrations, + ...nonWebIntegrations, ], ); testBefore( - integrations: integrations, - beforeIntegration: WidgetsFlutterBindingIntegration, - afterIntegration: OnErrorIntegration); + integrations: Sentry.currentHub.options.integrations, + beforeIntegration: RunZonedGuardedIntegration, + afterIntegration: WidgetsFlutterBindingIntegration); await Sentry.close(); });