Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
set current threadId when theres no mechanism to rely on (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Feb 21, 2020
1 parent b05a892 commit c3785de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Deque<SentryException> extractExceptionQueue(final @NotNull Throwable throwable)
thread = exceptionMechanismThrowable.getThread();
} else {
exceptionMechanism = null;
thread = null;
thread = Thread.currentThread();
}

SentryException exception = getSentryException(currentThrowable, exceptionMechanism, thread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,27 @@ class SentryExceptionFactoryTest {
assertEquals("SentryExceptionFactoryTest\$InnerClassThrowable", queue.first.type)
}

@Test
fun `when exception has no mechanism, it should get and set the current threadId`() {
val threadId = Thread.currentThread().id
val exception = Exception("message", Exception("cause"))
val queue = sut.extractExceptionQueue(exception)

assertEquals(threadId, queue.first.threadId)
}

@Test
fun `when exception has a mechanism, it should get and set the mechanism's threadId`() {
val exception = Exception("message")
val mechanism = Mechanism()
mechanism.type = "ANR"
val thread = Thread()
val throwable = ExceptionMechanismException(mechanism, exception, thread)

val queue = sut.extractExceptionQueue(throwable)

assertEquals(thread.id, queue.first.threadId)
}

private inner class InnerClassThrowable constructor(cause: Throwable? = null) : Throwable(cause)
}

0 comments on commit c3785de

Please sign in to comment.