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

exceptions should be sorted oldest to newest #370

Merged
merged 1 commit into from
Apr 20, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ List<SentryException> getSentryExceptions(final @NotNull Throwable throwable) {
/**
* Transforms a {@link Throwable} into a Queue of {@link SentryException}.
*
* <p>Exceptions are stored in the queue from the most recent one to the oldest one.
* <p>Multiple values represent chained exceptions and should be sorted oldest to newest.
*
* @param throwable throwable to transform in a queue of exceptions.
* @return a queue of exception with StackTrace.
Expand Down Expand Up @@ -130,7 +130,7 @@ Deque<SentryException> extractExceptionQueue(final @NotNull Throwable throwable)
}

SentryException exception = getSentryException(currentThrowable, exceptionMechanism, thread);
exceptions.add(exception);
exceptions.addFirst(exception);
currentThrowable = currentThrowable.getCause();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class SentryExceptionFactoryTest {
}

@Test
fun `when exception has a cause, ensure conversion queue keeps order`() {
fun `when exception is nested, it should be sorted oldest to newest`() {
val exception = Exception("message", Exception("cause"))
val queue = sut.extractExceptionQueue(exception)

assertEquals("message", queue.first.value)
assertEquals("cause", queue.last.value)
assertEquals("cause", queue.first.value)
assertEquals("message", queue.last.value)
}

@Test
Expand Down