Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions sentry-core/src/main/java/io/sentry/core/SentryEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions sentry-core/src/test/java/io/sentry/core/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -653,6 +654,15 @@ class SentryClientTest {
override fun isConnected(): Boolean = false
}

private fun createNonHandledException(): List<SentryException> {
val exception = SentryException().apply {
mechanism = Mechanism().apply {
isHandled = false
}
}
return listOf(exception)
}

internal class CustomCachedApplyScopeDataHint : Cached, ApplyScopeData

internal class DiskFlushNotificationHint : DiskFlushNotification {
Expand Down
22 changes: 11 additions & 11 deletions sentry-core/src/test/java/io/sentry/core/SentryEventTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -58,26 +51,33 @@ 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
assertFalse(event.isCrashed)
}

@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)
}
}