Skip to content

Commit 31f1837

Browse files
committed
Keep original exception class and message as a message for the Enhanced Expection
1 parent 3c91684 commit 31f1837

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

rxjava2debug/src/main/java/com/akaita/java/rxjava2debug/ExceptionUtils.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.akaita.java.rxjava2debug;
1818

1919
import io.reactivex.annotations.NonNull;
20-
import io.reactivex.annotations.Nullable;
2120

2221
import java.util.LinkedList;
2322
import java.util.List;
@@ -27,7 +26,7 @@ class ExceptionUtils {
2726
static Throwable setRootCause(@NonNull Throwable throwable, @NonNull Throwable rootCause) {
2827
List<Throwable> causes = listCauses(throwable);
2928
causes.add(rootCause);
30-
return collapseCauses(causes);
29+
return reverseAndCollapseCauses(causes);
3130
}
3231

3332
@NonNull
@@ -42,14 +41,22 @@ private static List<Throwable> listCauses(@NonNull Throwable throwable) {
4241
}
4342

4443
@NonNull
45-
private static Throwable collapseCauses(@NonNull List<Throwable> causes) {
44+
private static Throwable reverseAndCollapseCauses(@NonNull List<Throwable> causes) {
4645
if (causes.size() == 0) {
4746
return new RuntimeException("Empty list of causes");
4847
}
4948

49+
String originalEnhancedMessage = causes.get(causes.size() - 1).getLocalizedMessage();
50+
String topMessage = "caused by " + originalEnhancedMessage;
51+
5052
Throwable topThrowable = null;
5153
for (int i = causes.size() - 1; i >= 0; i--) {
52-
topThrowable = new Throwable(causes.get(i).getMessage(), topThrowable);
54+
if (i > 0) {
55+
topThrowable = new Throwable(causes.get(i).getMessage(), topThrowable);
56+
} else {
57+
topThrowable = new Throwable(topMessage, topThrowable);
58+
}
59+
5360
if (causes.get(i).getStackTrace() != null) {
5461
// This array should never be null, if everybody follows the Java spec
5562
// Sometimes this part of the spec is not followed, so we better protect ourselves

rxjava2debug/src/main/java/com/akaita/java/rxjava2debug/RxJava2Debug.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public static Throwable getEnhancedStackTrace(@NonNull Throwable original) {
7070
RxJavaAssemblyException assembledException = RxJavaAssemblyException.find(original);
7171
if (assembledException != null) {
7272
StackTraceElement[] clearStack = parseStackTrace(assembledException, basePackages);
73-
Throwable clearException = new Throwable();
73+
String enhancedMessage = original.toString();
74+
75+
Throwable clearException = new Throwable(enhancedMessage);
7476
clearException.setStackTrace(clearStack);
7577
enhanced = setRootCause(original, clearException);
7678
}

0 commit comments

Comments
 (0)