diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-24 16:43:10 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-24 16:43:10 +0100 |
commit | bc239065f94548814717e2d07588696ee261c1e3 (patch) | |
tree | 467b1cc66f9212e31df5491545b6276f2136fddd /src/main/java | |
parent | dffba2bb9abeb84e50816b69ea6f878ba9fc3d3f (diff) | |
download | skyhanni-bc239065f94548814717e2d07588696ee261c1e3.tar.gz skyhanni-bc239065f94548814717e2d07588696ee261c1e3.tar.bz2 skyhanni-bc239065f94548814717e2d07588696ee261c1e3.zip |
Fixed wrong BuildList in part of stack trace. Cleanup error manager code.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt | 16 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt | 129 |
2 files changed, 76 insertions, 69 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt index 5ede5acf7..977d041fa 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt @@ -10,13 +10,16 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.RenderItemTooltipEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.ConditionalUtils.onToggle import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.isRune +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils @@ -139,9 +142,8 @@ object EstimatedItemValue { } private fun updateItem(item: ItemStack) { - val oldData = cache[item] - if (oldData != null) { - display = oldData + cache[item]?.let { + display = it lastToolTipTime = System.currentTimeMillis() return } @@ -161,8 +163,12 @@ object EstimatedItemValue { val newDisplay = try { draw(item) } catch (e: Exception) { - ChatUtils.debug("Estimated Item Value error: ${e.message}") - e.printStackTrace() + ErrorManager.logErrorWithData( + e, "Error in Estimated Item Value renderer", + "item" to item, + "itemName" to item.itemName, + "getInternalName" to item.getInternalName(), + ) listOf() } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt index 1c37d5249..7196dda72 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -17,13 +17,45 @@ object ErrorManager { private val fullErrorMessages = mutableMapOf<String, String>() private var cache = TimeLimitedSet<Pair<String, Int>>(10.minutes) + private val breakAfter = listOf( + "at at.hannibal2.skyhanni.config.commands.Commands\$createCommand", + "at net.minecraftforge.fml.common.eventhandler.EventBus.post", + ) + + private val replace = mapOf( + "at.hannibal2.skyhanni" to "SH", + "io.mouberry,notenoughupdates" to "NEU", + "net.minecraft." to "MC.", + "net.minecraftforge.fml." to "FML.", + ) + + private val ignored = listOf( + "at java.lang.Thread.run", + "at java.util.concurrent.", + "at java.lang.reflect.", + "at net.minecraft.network.", + "at net.minecraft.client.Minecraft.addScheduledTask(", + "at net.minecraftforge.fml.common.network.handshake.", + "at net.minecraftforge.fml.common.eventhandler.", + "at net.fabricmc.devlaunchinjector.", + "at io.netty.", + "at com.google.gson.internal.", + "at sun.reflect.", + + "at at.hannibal2.skyhanni.config.commands.SimpleCommand.", + "at at.hannibal2.skyhanni.config.commands.Commands\$createCommand\$1.processCommand", + "at at.hannibal2.skyhanni.test.command.ErrorManager.logError", + "at at.hannibal2.skyhanni.events.LorenzEvent.postAndCatchAndBlock", + "at net.minecraft.launchwrapper.", + ) + fun resetCache() { cache.clear() } fun skyHanniError(message: String): Nothing { val exception = IllegalStateException(message) - logError(exception, message) + logErrorWithData(exception, message) throw exception } @@ -47,7 +79,7 @@ object ErrorManager { } ?: "Error id not found!") } - @Deprecated("Use data as well", ReplaceWith("logErrorStateWithData(userMessage, internalMessage)")) + @Deprecated("Use data as well", ReplaceWith("ErrorManager.logErrorStateWithData(userMessage, internalMessage)")) fun logErrorState(userMessage: String, internalMessage: String) { logError(IllegalStateException(internalMessage), userMessage, ignoreErrorCache = false, noStackTrace = false) } @@ -62,7 +94,7 @@ object ErrorManager { logError(IllegalStateException(internalMessage), userMessage, ignoreErrorCache, noStackTrace, *extraData) } - @Deprecated("Use data as well", ReplaceWith("logErrorWithData()")) + @Deprecated("Use data as well", ReplaceWith("ErrorManager.logErrorWithData(throwable, message)")) fun logError(throwable: Throwable, message: String) { logError(throwable, message, ignoreErrorCache = false, noStackTrace = false) } @@ -103,7 +135,7 @@ object ErrorManager { stackTrace = "<no stack trace>" } else { fullStackTrace = throwable.getCustomStackTrace(true).joinToString("\n") - stackTrace = throwable.getCustomStackTrace(false).joinToString("\n").removeSpam() + stackTrace = throwable.getCustomStackTrace(false).joinToString("\n") } val randomId = UUID.randomUUID().toString() @@ -142,70 +174,39 @@ object ErrorManager { } else "" return extraDataString } -} - -private fun Throwable.getCustomStackTrace(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", - "net.minecraft." to "MC.", - "net.minecraftforge.fml." to "FML.", - ) - for (traceElement in stackTrace) { - var text = "\tat $traceElement" - if (!full && text in parent) { - println("broke at: $text") - break - } - if (!full) { - for ((from, to) in replace) { - text = text.replace(from, to) + private fun Throwable.getCustomStackTrace( + fullStackTrace: Boolean, + parent: List<String> = emptyList() + ): List<String> = buildList { + add("Caused by ${this@getCustomStackTrace.javaClass.name}: $message") + + for (traceElement in stackTrace) { + val text = "\tat $traceElement" + if (!fullStackTrace && text in parent) { + println("broke at: $text") + break } + var visualText = text + if (!fullStackTrace) { + for ((from, to) in replace) { + visualText = visualText.replace(from, to) + } + } + if (!fullStackTrace && breakAfter.any { text.contains(it) }) { + break + } + if (ignored.any { text.contains(it) }) continue + add(visualText) } - add(text) - if (!full && breakAfter.any { text.contains(it) }) { - println("breakAfter: $text") - break - } - } - if (this === cause) { - add("Infinite recurring causes") - return@buildList - } + if (this === cause) { + add("<Infinite recurring causes>") + return@buildList + } - cause?.let { - addAll(it.getCustomStackTrace(full, this)) + cause?.let { + addAll(it.getCustomStackTrace(fullStackTrace, 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\$", - ".ErrorManager.logErrorState(ErrorManager.kt:51)", - "LorenzEvent.postWithoutCatch(LorenzEvent.kt:24)", - "LorenzEvent.postAndCatch(LorenzEvent.kt:15)", - "at net.minecraft.launchwrapper.", - "at net.fabricmc.devlaunchinjector.", - "at SH.events.LorenzEvent.postAndCatchAndBlock(LorenzEvent.kt:28)", - "at SH.events.LorenzEvent.postAndCatchAndBlock\$default(LorenzEvent.kt:18)", - "at SH.events.LorenzEvent.postAndCatch(LorenzEvent.kt:16)", - ) - return split("\n").filter { line -> !ignored.any { line.contains(it) } }.joinToString("\n") -} |