aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/test/command
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-06-22 13:00:47 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-06-22 13:00:47 +0200
commit3e7aa9855489888283b6c53ce14002fe38d04dbe (patch)
tree9300e8176ac357f0c5637209196dd65f4c287d5c /src/main/java/at/hannibal2/skyhanni/test/command
parent47ac0f99f9d482c3ab3baf794d9ebf03fbee3d6b (diff)
downloadskyhanni-3e7aa9855489888283b6c53ce14002fe38d04dbe.tar.gz
skyhanni-3e7aa9855489888283b6c53ce14002fe38d04dbe.tar.bz2
skyhanni-3e7aa9855489888283b6c53ce14002fe38d04dbe.zip
better error handling
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test/command')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt73
1 files changed, 66 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt
index a8c6660f3..575a2e4fe 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt
@@ -4,12 +4,14 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
import com.google.common.cache.CacheBuilder
+import net.minecraft.client.Minecraft
import java.util.*
import java.util.concurrent.TimeUnit
object CopyErrorCommand {
// random id -> error message
private val errorMessages = mutableMapOf<String, String>()
+ private val fullErrorMessages = mutableMapOf<String, String>()
private var cache =
CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build<Pair<String, Int>, Unit>()
@@ -20,22 +22,34 @@ object CopyErrorCommand {
return
}
- LorenzUtils.chat(errorMessages[array[0]]?.let {
+ val id = array[0]
+ val fullErrorMessage = LorenzUtils.isControlKeyDown()
+ val errorMessage = if (fullErrorMessage) {
+ fullErrorMessages[id]
+ } else {
+ errorMessages[id]
+ }
+ val name = if (fullErrorMessage) "Ful error" else "Error"
+ LorenzUtils.chat(errorMessage?.let {
OSUtils.copyToClipboard(it)
- "§e[SkyHanni] Error copied into the clipboard, please report it on the SkyHanni discord!"
+ "§e[SkyHanni] $name copied into the clipboard, please report it on the SkyHanni discord!"
} ?: "§c[SkyHanni] Error id not found!")
}
fun logError(error: Throwable, message: String) {
+ Minecraft.getMinecraft().thePlayer ?: throw Error(message, error)
+
val pair = error.stackTrace[0].let { it.fileName to it.lineNumber }
- if (cache.getIfPresent(pair) != null) return
+// if (cache.getIfPresent(pair) != null) return
cache.put(pair, Unit)
- val stackTrace = error.stackTraceToString().removeSpam()
+ val fullStackTrace = error.getExactStackTrace(true).joinToString("\n")
+ val stackTrace = error.getExactStackTrace(false).joinToString("\n").removeSpam()
val randomId = UUID.randomUUID().toString()
- errorMessages[randomId] =
- "```\nSkyHanni ${SkyHanniMod.version}: $message\n \n$stackTrace```"
+ errorMessages[randomId] = "```\nSkyHanni ${SkyHanniMod.version}: $message\n \n$stackTrace\n```"
+ fullErrorMessages[randomId] =
+ "```\nSkyHanni ${SkyHanniMod.version}: $message\n(full stack trace)\n \n$fullStackTrace\n```"
LorenzUtils.clickableChat(
"§c[SkyHanni ${SkyHanniMod.version}]: $message. Click here to copy the error into the clipboard.",
@@ -44,12 +58,57 @@ object CopyErrorCommand {
}
}
+private fun Throwable.getExactStackTrace(full: Boolean, parent: List<String> = emptyList()): List<String> = buildList {
+ add("Caused by " + javaClass.name + ": $message")
+
+ val breakAfter = listOf(
+ "at net.minecraftforge.client.ClientCommandHandler.executeCommand(",
+ )
+ val replace = mapOf(
+ "io.mouberry,notenoughupdates" to "NEU",
+ "at.hannibal2.skyhanni" to "SH",
+ )
+
+ for (traceElement in stackTrace) {
+ var text = "\tat $traceElement"
+ if (!full) {
+ if (text in parent) {
+ println("broke at: $text")
+ break
+ }
+ }
+ if (!full) {
+ for ((from, to) in replace) {
+ text = text.replace(from, to)
+ }
+ }
+ add(text)
+ if (!full) {
+ if (breakAfter.any { text.contains(it) }) {
+ println("breakAfter: $text")
+ break
+ }
+ }
+ }
+
+ cause?.let {
+ addAll(it.getExactStackTrace(full, this))
+ }
+}
+
private fun String.removeSpam(): String {
val ignored = listOf(
"at io.netty.",
"at net.minecraft.network.",
"at net.minecraftforge.fml.common.network.handshake.",
"at java.lang.Thread.run",
+ "at com.google.gson.internal.",
+ "at net.minecraftforge.fml.common.eventhandler.",
+ "at java.util.concurrent.",
+ "at sun.reflect.",
+ "at net.minecraft.client.Minecraft.addScheduledTask(",
+ "at java.lang.reflect.",
+ "at at.hannibal2.skyhanni.config.commands.Commands\$",
)
- return split("\r\n\t").filter { line -> !ignored.any { line.startsWith(it) } }.joinToString("\n")
+ return split("\n").filter { line -> !ignored.any { line.contains(it) } }.joinToString("\n")
}