diff --git a/sentry-core/src/main/java/io/sentry/core/SentryEvent.java b/sentry-core/src/main/java/io/sentry/core/SentryEvent.java index b4f028b29..6623856ce 100644 --- a/sentry-core/src/main/java/io/sentry/core/SentryEvent.java +++ b/sentry-core/src/main/java/io/sentry/core/SentryEvent.java @@ -330,14 +330,11 @@ public void setDebugMeta(DebugMeta debugMeta) { } /** - * Returns true if Level is Fatal or any exception was unhandled by the user. + * Returns true if any exception was unhandled by the user. * * @return true if its crashed or false otherwise */ public boolean isCrashed() { - if (level == SentryLevel.FATAL) { - return true; - } if (exception != null) { for (SentryException e : exception.getValues()) { if (e.getMechanism() != null diff --git a/sentry-core/src/test/java/io/sentry/core/SentryClientTest.kt b/sentry-core/src/test/java/io/sentry/core/SentryClientTest.kt index 560ed7e02..32ca1779d 100644 --- a/sentry-core/src/test/java/io/sentry/core/SentryClientTest.kt +++ b/sentry-core/src/test/java/io/sentry/core/SentryClientTest.kt @@ -17,6 +17,7 @@ import io.sentry.core.hints.Cached import io.sentry.core.hints.DiskFlushNotification import io.sentry.core.hints.SessionEndHint import io.sentry.core.hints.SessionUpdateHint +import io.sentry.core.protocol.Mechanism import io.sentry.core.protocol.Request import io.sentry.core.protocol.SdkVersion import io.sentry.core.protocol.SentryException @@ -465,11 +466,11 @@ class SentryClientTest { } @Test - fun `When event is Fatal or not handled, mark session as Crashed`() { + fun `When event is non handled, mark session as Crashed`() { val scope = Scope(fixture.sentryOptions) scope.startSession().current val event = SentryEvent().apply { - level = SentryLevel.FATAL + exceptions = createNonHandledException() } fixture.getSut().updateSessionData(event, null, scope) scope.withSession { @@ -478,7 +479,7 @@ class SentryClientTest { } @Test - fun `When event is non fatal, keep level as it is`() { + fun `When event is handled, keep level as it is`() { val scope = Scope(fixture.sentryOptions) val session = scope.startSession().current val level = session.status @@ -488,11 +489,11 @@ class SentryClientTest { } @Test - fun `When event is Fatal, increase errorCount`() { + fun `When event is non handled, increase errorCount`() { val scope = Scope(fixture.sentryOptions) scope.startSession().current val event = SentryEvent().apply { - level = SentryLevel.FATAL + exceptions = createNonHandledException() } fixture.getSut().updateSessionData(event, null, scope) scope.withSession { @@ -516,7 +517,7 @@ class SentryClientTest { } @Test - fun `When event is non fatal nor errored, do not increase errorsCount`() { + fun `When event is handled and not errored, do not increase errorsCount`() { val scope = Scope(fixture.sentryOptions) val session = scope.startSession().current val errorCount = session.errorCount() @@ -569,7 +570,7 @@ class SentryClientTest { val sut = fixture.getSut() val event = SentryEvent().apply { - level = SentryLevel.FATAL + exceptions = createNonHandledException() } val scope = Scope(fixture.sentryOptions) scope.startSession() @@ -586,7 +587,7 @@ class SentryClientTest { val sut = fixture.getSut() val event = SentryEvent().apply { - level = SentryLevel.FATAL + exceptions = createNonHandledException() } val scope = Scope(fixture.sentryOptions) scope.startSession() @@ -602,7 +603,7 @@ class SentryClientTest { val sut = fixture.getSut() val event = SentryEvent().apply { - level = SentryLevel.FATAL + exceptions = createNonHandledException() } val scope = Scope(fixture.sentryOptions) scope.startSession().current @@ -653,6 +654,15 @@ class SentryClientTest { override fun isConnected(): Boolean = false } + private fun createNonHandledException(): List { + val exception = SentryException().apply { + mechanism = Mechanism().apply { + isHandled = false + } + } + return listOf(exception) + } + internal class CustomCachedApplyScopeDataHint : Cached, ApplyScopeData internal class DiskFlushNotificationHint : DiskFlushNotification { diff --git a/sentry-core/src/test/java/io/sentry/core/SentryEventTest.kt b/sentry-core/src/test/java/io/sentry/core/SentryEventTest.kt index 229ce1878..2d8f6b66c 100644 --- a/sentry-core/src/test/java/io/sentry/core/SentryEventTest.kt +++ b/sentry-core/src/test/java/io/sentry/core/SentryEventTest.kt @@ -39,13 +39,6 @@ class SentryEventTest { assertEquals(expected, DateUtils.getTimestampIsoFormat(actual.timestamp)) } - @Test - fun `if level Fatal it should return isCrashed=true`() { - val event = SentryEvent() - event.level = SentryLevel.FATAL - assertTrue(event.isCrashed) - } - @Test fun `if mechanism is not handled, it should return isCrashed=true`() { val mechanism = Mechanism() @@ -58,11 +51,10 @@ class SentryEventTest { } @Test - fun `if mechanism is handled and level is not fatal, it should return isCrashed=false`() { + fun `if mechanism is handled, it should return isCrashed=false`() { val mechanism = Mechanism() mechanism.isHandled = true val event = SentryEvent() - event.level = SentryLevel.ERROR val factory = SentryExceptionFactory(mock()) val sentryExceptions = factory.getSentryExceptions(ExceptionMechanismException(mechanism, Throwable(), Thread())) event.exceptions = sentryExceptions @@ -70,14 +62,22 @@ class SentryEventTest { } @Test - fun `if mechanism nas not handled flag and level is not fatal, it should return isCrashed=false`() { + fun `if mechanism handled flag is null, it should return isCrashed=false`() { val mechanism = Mechanism() mechanism.isHandled = null val event = SentryEvent() - event.level = SentryLevel.ERROR val factory = SentryExceptionFactory(mock()) val sentryExceptions = factory.getSentryExceptions(ExceptionMechanismException(mechanism, Throwable(), Thread())) event.exceptions = sentryExceptions assertFalse(event.isCrashed) } + + @Test + fun `if mechanism is not set, it should return isCrashed=false`() { + val event = SentryEvent() + val factory = SentryExceptionFactory(mock()) + val sentryExceptions = factory.getSentryExceptions(RuntimeException(Throwable())) + event.exceptions = sentryExceptions + assertFalse(event.isCrashed) + } }