Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Enhancement: Call `toString()` on all non-serializable fields (#528)
* Fix: Always call `Flutter.onError` in order to not swallow messages (#533)
* Bump: Android SDK to 5.1.0-beta.6 (#535)
* Feat: Collect more information for exceptions collected via `FlutterError.onError` (#538)

# 6.0.0-beta.2

Expand Down
19 changes: 17 additions & 2 deletions flutter/lib/src/default_integrations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,31 @@ class FlutterErrorIntegration extends Integration<SentryFlutterOptions> {
void call(Hub hub, SentryFlutterOptions options) {
_defaultOnError = FlutterError.onError;
_integrationOnError = (FlutterErrorDetails errorDetails) async {
dynamic exception = errorDetails.exception;
final exception = errorDetails.exception;

options.logger(
SentryLevel.debug,
'Capture from onError $exception',
);

if (errorDetails.silent != true || options.reportSilentFlutterErrors) {
final context = errorDetails.context?.toDescription();

final collector = errorDetails.informationCollector?.call() ?? [];
final information =
(StringBuffer()..writeAll(collector, '\n')).toString();
final library = errorDetails.library;

// FlutterError doesn't crash the App.
final mechanism = Mechanism(type: 'FlutterError', handled: true);
final mechanism = Mechanism(
type: 'FlutterError',
handled: true,
data: {
if (context != null) 'context': context,
if (collector.isNotEmpty) 'information': information,
if (library != null) 'library': library,
},
);
final throwableMechanism = ThrowableMechanism(mechanism, exception);

var event = SentryEvent(
Expand Down
7 changes: 7 additions & 0 deletions flutter/test/default_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void main() {
final details = FlutterErrorDetails(
exception: throwable,
silent: silent,
context: DiagnosticsNode.message('while handling a gesture'),
library: 'sentry',
informationCollector: () => [DiagnosticsNode.message('foo bar')],
);
FlutterError.reportError(details);
}
Expand All @@ -64,6 +67,10 @@ void main() {
final throwableMechanism = event.throwableMechanism as ThrowableMechanism;
expect(throwableMechanism.mechanism.type, 'FlutterError');
expect(throwableMechanism.mechanism.handled, true);
expect(throwableMechanism.mechanism.data['library'], 'sentry');
expect(throwableMechanism.mechanism.data['context'],
'while handling a gesture');
expect(throwableMechanism.mechanism.data['information'], 'foo bar');
expect(throwableMechanism.throwable, exception);
});

Expand Down