diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ef7608a29..cb8e260a76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add support for exception aggregates for PlatformExceptions from Android ([#1999](https://github.com/getsentry/sentry-dart/pull/1999)) + ## 8.2.0 ### Enhancements diff --git a/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart b/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart index bffc6707b7..1b1624e364 100644 --- a/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart +++ b/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart @@ -95,9 +95,20 @@ class AndroidPlatformExceptionEventProcessor implements EventProcessor { jvmThreads.add(first); } + final eventExceptions = event.exceptions?.map((e) { + // TODO: Maybe this shouldn't be applied to all exceptions? + return e.copyWith( + mechanism: Mechanism( + type: 'chained', + exceptionId: jvmExceptions.length, + parentId: 0, + ), + ); + }); + return event.copyWith( exceptions: [ - ...?event.exceptions, + ...?eventExceptions, ...jvmExceptions, ], threads: [ @@ -140,15 +151,18 @@ class _JvmExceptionFactory { ...?jvmException.suppressed, ]; - return jvmExceptions.map((exception) { - return exception.toSentryException(nativePackageName); + return jvmExceptions.asMap().entries.map((indexedException) { + return indexedException.value + .toSentryException(nativePackageName, indexedException.key); }).toList(growable: false); } } extension on JvmException { MapEntry toSentryException( - String nativePackageName) { + String nativePackageName, + int index, + ) { String? exceptionType; String? module; final typeParts = type?.split('.'); @@ -173,6 +187,12 @@ extension on JvmException { stackTrace: SentryStackTrace( frames: stackFrames.reversed.toList(growable: false), ), + mechanism: Mechanism( + type: index == 0 ? "sentry-flutter" : "chained", + exceptionId: index, + parentId: index == 0 ? null : index - 1, + isExceptionGroup: index == 0 ? true : null, + ), ); String threadName;