Skip to content

Commit

Permalink
Capture Future errors for Flutter Web automatically (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Nov 28, 2022
1 parent a510d1d commit 691aa3b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Capture Future errors for Flutter Web automatically ([#1152](https://github.com/getsentry/sentry-dart/pull/1152))

### Features

- User Interaction transactions and breadcrumbs ([#1137](https://github.com/getsentry/sentry-dart/pull/1137))
Expand Down
5 changes: 0 additions & 5 deletions flutter/lib/src/integrations/flutter_error_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class FlutterErrorIntegration extends Integration<SentryFlutterOptions> {
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);

Expand Down
8 changes: 7 additions & 1 deletion flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions flutter/test/integrations/flutter_error_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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'],
Expand Down
48 changes: 33 additions & 15 deletions flutter/test/sentry_flutter_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -69,6 +74,7 @@ void main() {
...androidIntegrations,
...nativeIntegrations,
...platformAgnosticIntegrations,
...nonWebIntegrations,
],
shouldNotHaveIntegrations: iOsAndMacOsIntegrations);

Expand Down Expand Up @@ -109,6 +115,7 @@ void main() {
...iOsAndMacOsIntegrations,
...nativeIntegrations,
...platformAgnosticIntegrations,
...nonWebIntegrations,
],
shouldNotHaveIntegrations: androidIntegrations,
);
Expand Down Expand Up @@ -147,6 +154,7 @@ void main() {
...iOsAndMacOsIntegrations,
...nativeIntegrations,
...platformAgnosticIntegrations,
...nonWebIntegrations,
],
shouldNotHaveIntegrations: androidIntegrations,
);
Expand Down Expand Up @@ -181,7 +189,10 @@ void main() {

testConfiguration(
integrations: integrations,
shouldHaveIntegrations: platformAgnosticIntegrations,
shouldHaveIntegrations: [
...platformAgnosticIntegrations,
...nonWebIntegrations,
],
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
Expand Down Expand Up @@ -219,7 +230,10 @@ void main() {

testConfiguration(
integrations: integrations,
shouldHaveIntegrations: platformAgnosticIntegrations,
shouldHaveIntegrations: [
...platformAgnosticIntegrations,
...nonWebIntegrations,
],
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 691aa3b

Please sign in to comment.