Skip to content

Capture Future errors for Flutter Web automatically #1152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really needed anymore, people are used to scrolling down and reading all the available context.

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
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