diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index 06152692d51..a65ffa00ed6 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -215,14 +215,22 @@ - (SentryEvent *)buildExceptionEvent:(NSException *)exception event.exceptions = @[ sentryException ]; + SentryMechanism *mechanism = [[SentryMechanism alloc] initWithType:@"NSException"]; + mechanism.desc = exception.reason; + mechanism.data = sentry_sanitize(exception.userInfo); + #if TARGET_OS_OSX // When a exception class is SentryUseNSExceptionCallstackWrapper, we should use the thread from // it if ([exception isKindOfClass:[SentryUseNSExceptionCallstackWrapper class]]) { event.threads = [(SentryUseNSExceptionCallstackWrapper *)exception buildThreads]; + event.level = kSentryLevelFatal; + + // Only exceptions through `_crashOnExceptions` are guaranteed to be unhandled + mechanism.handled = @(NO); } #endif - + sentryException.mechanism = mechanism; [self setUserInfo:exception.userInfo withEvent:event]; return event; } diff --git a/Sources/Sentry/SentryCrashExceptionApplicationHelper.m b/Sources/Sentry/SentryCrashExceptionApplicationHelper.m index 3ea3c7e79e1..3d7be8c2373 100644 --- a/Sources/Sentry/SentryCrashExceptionApplicationHelper.m +++ b/Sources/Sentry/SentryCrashExceptionApplicationHelper.m @@ -8,6 +8,8 @@ # import "SentryDependencyContainer.h" # import "SentrySDK+Private.h" # import "SentrySDK.h" +# import "SentryScope.h" +# import "SentrySwift.h" @implementation SentryCrashExceptionApplicationHelper @@ -21,9 +23,11 @@ + (void)reportException:(NSException *)exception + (void)_crashOnException:(NSException *)exception { - [SentrySDK captureCrashOnException:exception]; + SentryScope *scope = [[SentryScope alloc] initWithScope:SentrySDK.currentHub.scope]; + [scope setLevel:kSentryLevelFatal]; + [SentrySDK captureCrashOnException:exception withScope:scope]; # if !(SENTRY_TEST || SENTRY_TEST_CI) - abort(); +// abort(); # endif } diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index a6b44c64051..1214d49c8db 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -398,7 +398,7 @@ + (SentryId *)captureException:(NSException *)exception withScope:(SentryScope * #if TARGET_OS_OSX -+ (SentryId *)captureCrashOnException:(NSException *)exception ++ (SentryId *)captureCrashOnException:(NSException *)exception withScope:(SentryScope *)scope { SentryUseNSExceptionCallstackWrapper *wrappedException = [[SentryUseNSExceptionCallstackWrapper alloc] @@ -406,7 +406,7 @@ + (SentryId *)captureCrashOnException:(NSException *)exception reason:exception.reason userInfo:exception.userInfo callStackReturnAddresses:exception.callStackReturnAddresses]; - return [SentrySDK captureException:wrappedException withScope:SentrySDK.currentHub.scope]; + return [SentrySDK captureException:wrappedException withScope:scope]; } #endif // TARGET_OS_OSX diff --git a/Sources/Sentry/include/SentrySDK+Private.h b/Sources/Sentry/include/SentrySDK+Private.h index 011dfa67e67..3170b0f0372 100644 --- a/Sources/Sentry/include/SentrySDK+Private.h +++ b/Sources/Sentry/include/SentrySDK+Private.h @@ -67,7 +67,8 @@ NS_ASSUME_NONNULL_BEGIN * */ + (SentryId *)captureCrashOnException:(NSException *)exception - NS_SWIFT_NAME(captureCrashOn(exception:)); + withScope:(SentryScope *)scope + NS_SWIFT_NAME(captureCrashOn(exception:withScope:)); #endif // TARGET_OS_OSX diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 3ca416376bf..af9afdfa85a 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -1006,7 +1006,7 @@ class SentrySDKTests: XCTestCase { func testCaptureCrashOnException() { givenSdkWithHub() - SentrySDK.captureCrashOn(exception: fixture.exception) + SentrySDK.captureCrashOn(exception: fixture.exception, withScope: fixture.scope) let client = fixture.client XCTAssertEqual(1, client.captureExceptionWithScopeInvocations.count)