Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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 @@ -7,6 +7,10 @@
- Feat: Introduce `Hint` data bag ([#1136](https://github.com/getsentry/sentry-dart/pull/1136))
- Feat: Use `Hint` for screenshots ([#1165](https://github.com/getsentry/sentry-dart/pull/1165))

### Enhancements

- Enha: Exceptions not handled by user code should be `unhandled: true` #1186 ([#1186](https://github.com/getsentry/sentry-dart/pull/1186))
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 🚫 The changelog entry seems to be part of an already released section ## 7.0.0.
    Consider moving the entry to the ## Unreleased section, please.


### Fixes

- Fix: Remove `SentryOptions` related parameters from classes which also take `Hub` as a parameter (#816)
Expand Down
5 changes: 3 additions & 2 deletions dart/lib/src/isolate_error_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ Future<void> handleIsolateError(
stackTrace: stackTrace == null ? null : StackTrace.fromString(stackTrace),
);

// Isolate errors don't crash the App.
final mechanism = Mechanism(type: 'isolateError', handled: true);
// Isolate errors don't crash the app, but are set to handled false, as
// users did not handle them manually
final mechanism = Mechanism(type: 'isolateError', handled: false);
final throwableMechanism = ThrowableMechanism(mechanism, throwable);
final event = SentryEvent(
throwable: throwableMechanism,
Expand Down
5 changes: 3 additions & 2 deletions dart/lib/src/run_zoned_guarded_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class RunZonedGuardedIntegration extends Integration {
stackTrace: stackTrace,
);

// runZonedGuarded doesn't crash the App.
final mechanism = Mechanism(type: 'runZonedGuarded', handled: true);
// runZonedGuarded doesn't crash the App, but since it is not handled by
// users manually, it is marked as not handled
final mechanism = Mechanism(type: 'runZonedGuarded', handled: false);
final throwableMechanism = ThrowableMechanism(mechanism, exception);

final event = SentryEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void main() {
);
expect(event.exceptions?.first.mechanism?.type, 'OSError');
expect(event.exceptions?.first.mechanism?.meta['errno']['number'], 54);
expect(event.exceptions?.first.mechanism?.handled, isNull);
});

test('adds OSError SentryException for $FileSystemException', () async {
Expand All @@ -92,6 +93,7 @@ void main() {
);
expect(event.exceptions?.first.mechanism?.type, 'OSError');
expect(event.exceptions?.first.mechanism?.meta['errno']['number'], 42);
expect(event.exceptions?.first.mechanism?.handled, isNull);
});
});
}
Expand Down
2 changes: 2 additions & 0 deletions dart/test/http_client/failed_request_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void main() {
expect(exception?.stackTrace, isNotNull);
expect(exception?.stackTrace!.snapshot, isNull);
expect(mechanism?.type, 'SentryHttpClient');
expect(mechanism?.handled, isNull);

final request = eventCall.request;
expect(request, isNotNull);
Expand Down Expand Up @@ -107,6 +108,7 @@ void main() {
mechanism?.description,
'HTTP Client Error with status code: 404',
);
expect(mechanism?.handled, isNull);

expect(exception?.type, 'SentryHttpClientError');
expect(
Expand Down
1 change: 1 addition & 0 deletions dio/test/failed_request_interceptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void main() {
final throwable =
fixture.hub.captureExceptionCalls.first.throwable as ThrowableMechanism;
expect(throwable.mechanism.type, 'SentryDioClientAdapter');
expect(throwable.mechanism.handled, isNull);
expect(throwable.throwable, error);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FlutterErrorIntegration extends Integration<SentryFlutterOptions> {
// FlutterError doesn't crash the App.
final mechanism = Mechanism(
type: 'FlutterError',
handled: true,
handled: false,
);
final throwableMechanism = ThrowableMechanism(mechanism, exception);

Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/integrations/on_error_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OnErrorIntegration implements Integration<SentryFlutterOptions> {
_defaultOnError = wrapper.onError;

_integrationOnError = (Object exception, StackTrace stackTrace) {
final handled = _defaultOnError?.call(exception, stackTrace) ?? true;
final handled = _defaultOnError?.call(exception, stackTrace) ?? false;

// As per docs, the app might crash on some platforms
// after this is called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
}) {
// replace default error otherwise it fails on testing
FlutterError.onError =
handler ?? (FlutterErrorDetails errorDetails) async {};
handler ??= (FlutterErrorDetails errorDetails) async {};

when(fixture.hub.captureEvent(captureAny))
.thenAnswer((_) => Future.value(SentryId.empty()));
Expand Down Expand Up @@ -57,7 +57,7 @@ void main() {

final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
expect(throwableMechanism.mechanism.type, 'FlutterError');
expect(throwableMechanism.mechanism.handled, true);
expect(throwableMechanism.mechanism.handled, false);
expect(throwableMechanism.throwable, exception);

expect(event.contexts['flutter_error_details']['library'], 'sentry');
Expand Down Expand Up @@ -91,7 +91,7 @@ void main() {

final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
expect(throwableMechanism.mechanism.type, 'FlutterError');
expect(throwableMechanism.mechanism.handled, true);
expect(throwableMechanism.mechanism.handled, false);

expect(event.contexts['flutter_error_details']['library'], 'sentry');
expect(event.contexts['flutter_error_details']['context'],
Expand All @@ -115,7 +115,7 @@ void main() {

final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
expect(throwableMechanism.mechanism.type, 'FlutterError');
expect(throwableMechanism.mechanism.handled, true);
expect(throwableMechanism.mechanism.handled, false);
expect(throwableMechanism.mechanism.data['hint'], isNull);

expect(event.contexts['flutter_error_details'], isNull);
Expand Down
31 changes: 27 additions & 4 deletions flutter/test/integrations/on_error_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ void main() {
required Object exception,
required StackTrace stackTrace,
ErrorCallback? handler,
bool useFallbackHandler = true,
}) {
fixture.platformDispatcherWrapper.onError = handler ??
(_, __) {
return fixture.onErrorReturnValue;
};
if (handler != null) {
fixture.platformDispatcherWrapper.onError = handler;
} else if (useFallbackHandler) {
fixture.platformDispatcherWrapper.onError = (_, __) {
return fixture.onErrorReturnValue;
};
}

when(fixture.hub.captureEvent(captureAny,
stackTrace: captureAnyNamed('stackTrace')))
Expand Down Expand Up @@ -57,6 +61,24 @@ void main() {
expect(throwableMechanism.throwable, exception);
});

test('onError: no handler marks event as not handled', () async {
final exception = StateError('error');

_reportError(
exception: exception,
stackTrace: StackTrace.current,
useFallbackHandler: false);

final event = verify(
await fixture.hub
.captureEvent(captureAny, stackTrace: captureAnyNamed('stackTrace')),
).captured.first as SentryEvent;

final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
expect(throwableMechanism.mechanism.handled, isNotNull);
expect(throwableMechanism.mechanism.handled, false);
});

test('onError: handled is true if onError returns true', () async {
fixture.onErrorReturnValue = true;
final exception = StateError('error');
Expand All @@ -82,6 +104,7 @@ void main() {
).captured.first as SentryEvent;

final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
expect(throwableMechanism.mechanism.handled, isNotNull);
expect(throwableMechanism.mechanism.handled, false);
});

Expand Down