Skip to content

Commit f029fc8

Browse files
committed
Create a new exception instead of wrapping it
1 parent a669d79 commit f029fc8

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

src/main/java/com/lambda/mixin/CrashReportMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.lambda.config.AbstractSetting;
2222
import com.lambda.module.Module;
2323
import com.lambda.module.ModuleRegistry;
24-
import com.lambda.util.DynamicException;
24+
import com.lambda.util.DynamicExceptionKt;
2525
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
2626
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2727
import net.minecraft.client.MinecraftClient;
@@ -47,7 +47,7 @@ public class CrashReportMixin {
4747
@Inject(method = "<init>(Ljava/lang/String;Ljava/lang/Throwable;)V", at = @At("TAIL"))
4848
void injectConstructor(String message, Throwable cause, CallbackInfo ci) {
4949
if (!Lambda.INSTANCE.isDebug() && MinecraftClient.getInstance() != null) {
50-
this.cause = new DynamicException(cause);
50+
this.cause = DynamicExceptionKt.dynamicException(cause);
5151
}
5252
}
5353

src/main/kotlin/com/lambda/util/DynamicException.kt

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,19 @@
1818
package com.lambda.util
1919

2020
import com.lambda.util.DynamicReflectionSerializer.simpleRemappedName
21-
import java.io.PrintStream
22-
import java.io.PrintWriter
21+
import kotlin.collections.toTypedArray
2322

24-
class DynamicException(original: Throwable) : Throwable(original) {
25-
private fun Array<StackTraceElement>.remapClassNames() =
26-
map { element ->
23+
/**
24+
* Remaps the stacktrace in production to have readable, class, method and field names
25+
*/
26+
fun dynamicException(original: Throwable) = Throwable(original.localizedMessage)
27+
.apply {
28+
stackTrace = stackTrace.map { element ->
2729
StackTraceElement(
2830
element.className.simpleRemappedName,
2931
element.methodName.simpleRemappedName,
30-
element.fileName,
32+
element.fileName, // This is intentional, you don't need to remap the file name so might as well keep a reference of the class file name
3133
element.lineNumber
3234
)
3335
}.toTypedArray()
34-
35-
override fun printStackTrace(s: PrintStream) =
36-
stackTrace.forEach { s.println("\tat $it") }
37-
38-
override fun printStackTrace(s: PrintWriter) =
39-
stackTrace.forEach { s.println("\tat $it") }
40-
41-
override fun toString(): String = localizedMessage
42-
43-
init {
44-
stackTrace = stackTrace.remapClassNames()
45-
}
46-
}
36+
}

0 commit comments

Comments
 (0)