-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: associate event with transaction when thrown exception is not a …
- Loading branch information
1 parent
5fa4b52
commit 6a7e4bc
Showing
6 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.sentry.util; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@ApiStatus.Internal | ||
public final class ExceptionUtils { | ||
|
||
/** | ||
* Returns exception root cause or the exception itself if there are no causes | ||
* | ||
* @param throwable - the throwable | ||
* @return the root cause | ||
*/ | ||
public static @NotNull Throwable findRootCause(final @NotNull Throwable throwable) { | ||
Objects.requireNonNull(throwable, "throwable cannot be null"); | ||
Throwable rootCause = throwable; | ||
while (rootCause.getCause() != null && rootCause.getCause() != rootCause) { | ||
rootCause = rootCause.getCause(); | ||
} | ||
return rootCause; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.sentry.util | ||
|
||
import java.lang.RuntimeException | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ExceptionUtilsTest { | ||
|
||
@Test | ||
fun `returns same exception when there is no cause`() { | ||
val ex = RuntimeException() | ||
assertEquals(ex, ExceptionUtils.findRootCause(ex)) | ||
} | ||
|
||
@Test | ||
fun `returns first cause when there are multiple causes`() { | ||
val rootCause = RuntimeException() | ||
val cause = RuntimeException(rootCause) | ||
val ex = RuntimeException(cause) | ||
assertEquals(rootCause, ExceptionUtils.findRootCause(ex)) | ||
} | ||
} |