Skip to content

Commit 691aa3b

Browse files
authored
Capture Future errors for Flutter Web automatically (#1152)
1 parent a510d1d commit 691aa3b

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- Capture Future errors for Flutter Web automatically ([#1152](https://github.com/getsentry/sentry-dart/pull/1152))
8+
59
### Features
610

711
- User Interaction transactions and breadcrumbs ([#1137](https://github.com/getsentry/sentry-dart/pull/1137))

flutter/lib/src/integrations/flutter_error_integration.dart

-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class FlutterErrorIntegration extends Integration<SentryFlutterOptions> {
6060
final mechanism = Mechanism(
6161
type: 'FlutterError',
6262
handled: true,
63-
data: {
64-
if (flutterErrorDetails.isNotEmpty)
65-
'hint':
66-
'See "flutter_error_details" down below for more information'
67-
},
6863
);
6964
final throwableMechanism = ThrowableMechanism(mechanism, exception);
7065

flutter/lib/src/sentry_flutter.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ mixin SentryFlutter {
5252

5353
final platformDispatcher = PlatformDispatcher.instance;
5454
final wrapper = PlatformDispatcherWrapper(platformDispatcher);
55-
final isOnErrorSupported = wrapper.isOnErrorSupported(flutterOptions);
55+
56+
// Flutter Web don't capture [Future] errors if using [PlatformDispatcher.onError] and not
57+
// the [runZonedGuarded].
58+
// likely due to https://github.com/flutter/flutter/issues/100277
59+
final isOnErrorSupported = flutterOptions.platformChecker.isWeb
60+
? false
61+
: wrapper.isOnErrorSupported(flutterOptions);
5662

5763
// first step is to install the native integration and set default values,
5864
// so we are able to capture future errors.

flutter/test/integrations/flutter_error_integration_test.dart

-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ void main() {
5656
final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
5757
expect(throwableMechanism.mechanism.type, 'FlutterError');
5858
expect(throwableMechanism.mechanism.handled, true);
59-
expect(throwableMechanism.mechanism.data['hint'],
60-
'See "flutter_error_details" down below for more information');
6159
expect(throwableMechanism.throwable, exception);
6260

6361
expect(event.contexts['flutter_error_details']['library'], 'sentry');
@@ -92,8 +90,6 @@ void main() {
9290
final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
9391
expect(throwableMechanism.mechanism.type, 'FlutterError');
9492
expect(throwableMechanism.mechanism.handled, true);
95-
expect(throwableMechanism.mechanism.data['hint'],
96-
'See "flutter_error_details" down below for more information');
9793

9894
expect(event.contexts['flutter_error_details']['library'], 'sentry');
9995
expect(event.contexts['flutter_error_details']['context'],

flutter/test/sentry_flutter_test.dart

+33-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: invalid_use_of_internal_member
2+
13
import 'package:flutter_test/flutter_test.dart';
24
import 'package:package_info_plus/package_info_plus.dart';
35
import 'package:sentry_flutter/sentry_flutter.dart';
@@ -13,12 +15,15 @@ import 'sentry_flutter_util.dart';
1315
/// They don't depend on the underlying platform.
1416
final platformAgnosticIntegrations = [
1517
WidgetsFlutterBindingIntegration,
16-
OnErrorIntegration,
1718
FlutterErrorIntegration,
1819
LoadReleaseIntegration,
1920
DebugPrintIntegration,
2021
];
2122

23+
final nonWebIntegrations = [
24+
OnErrorIntegration,
25+
];
26+
2227
// These should only be added to Android
2328
final androidIntegrations = [
2429
LoadImageListIntegration,
@@ -69,6 +74,7 @@ void main() {
6974
...androidIntegrations,
7075
...nativeIntegrations,
7176
...platformAgnosticIntegrations,
77+
...nonWebIntegrations,
7278
],
7379
shouldNotHaveIntegrations: iOsAndMacOsIntegrations);
7480

@@ -109,6 +115,7 @@ void main() {
109115
...iOsAndMacOsIntegrations,
110116
...nativeIntegrations,
111117
...platformAgnosticIntegrations,
118+
...nonWebIntegrations,
112119
],
113120
shouldNotHaveIntegrations: androidIntegrations,
114121
);
@@ -147,6 +154,7 @@ void main() {
147154
...iOsAndMacOsIntegrations,
148155
...nativeIntegrations,
149156
...platformAgnosticIntegrations,
157+
...nonWebIntegrations,
150158
],
151159
shouldNotHaveIntegrations: androidIntegrations,
152160
);
@@ -181,7 +189,10 @@ void main() {
181189

182190
testConfiguration(
183191
integrations: integrations,
184-
shouldHaveIntegrations: platformAgnosticIntegrations,
192+
shouldHaveIntegrations: [
193+
...platformAgnosticIntegrations,
194+
...nonWebIntegrations,
195+
],
185196
shouldNotHaveIntegrations: [
186197
...androidIntegrations,
187198
...iOsAndMacOsIntegrations,
@@ -219,7 +230,10 @@ void main() {
219230

220231
testConfiguration(
221232
integrations: integrations,
222-
shouldHaveIntegrations: platformAgnosticIntegrations,
233+
shouldHaveIntegrations: [
234+
...platformAgnosticIntegrations,
235+
...nonWebIntegrations,
236+
],
223237
shouldNotHaveIntegrations: [
224238
...androidIntegrations,
225239
...iOsAndMacOsIntegrations,
@@ -265,13 +279,14 @@ void main() {
265279
...androidIntegrations,
266280
...iOsAndMacOsIntegrations,
267281
...nativeIntegrations,
282+
...nonWebIntegrations,
268283
],
269284
);
270285

271286
testBefore(
272-
integrations: integrations,
273-
beforeIntegration: WidgetsFlutterBindingIntegration,
274-
afterIntegration: OnErrorIntegration);
287+
integrations: Sentry.currentHub.options.integrations,
288+
beforeIntegration: RunZonedGuardedIntegration,
289+
afterIntegration: WidgetsFlutterBindingIntegration);
275290

276291
await Sentry.close();
277292
});
@@ -308,13 +323,14 @@ void main() {
308323
...androidIntegrations,
309324
...iOsAndMacOsIntegrations,
310325
...nativeIntegrations,
326+
...nonWebIntegrations,
311327
],
312328
);
313329

314330
testBefore(
315-
integrations: integrations,
316-
beforeIntegration: WidgetsFlutterBindingIntegration,
317-
afterIntegration: OnErrorIntegration);
331+
integrations: Sentry.currentHub.options.integrations,
332+
beforeIntegration: RunZonedGuardedIntegration,
333+
afterIntegration: WidgetsFlutterBindingIntegration);
318334

319335
await Sentry.close();
320336
});
@@ -351,13 +367,14 @@ void main() {
351367
...androidIntegrations,
352368
...iOsAndMacOsIntegrations,
353369
...nativeIntegrations,
370+
...nonWebIntegrations,
354371
],
355372
);
356373

357374
testBefore(
358-
integrations: integrations,
359-
beforeIntegration: WidgetsFlutterBindingIntegration,
360-
afterIntegration: OnErrorIntegration);
375+
integrations: Sentry.currentHub.options.integrations,
376+
beforeIntegration: RunZonedGuardedIntegration,
377+
afterIntegration: WidgetsFlutterBindingIntegration);
361378

362379
await Sentry.close();
363380
});
@@ -393,13 +410,14 @@ void main() {
393410
...androidIntegrations,
394411
...iOsAndMacOsIntegrations,
395412
...nativeIntegrations,
413+
...nonWebIntegrations,
396414
],
397415
);
398416

399417
testBefore(
400-
integrations: integrations,
401-
beforeIntegration: WidgetsFlutterBindingIntegration,
402-
afterIntegration: OnErrorIntegration);
418+
integrations: Sentry.currentHub.options.integrations,
419+
beforeIntegration: RunZonedGuardedIntegration,
420+
afterIntegration: WidgetsFlutterBindingIntegration);
403421

404422
await Sentry.close();
405423
});

0 commit comments

Comments
 (0)