diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-19 11:44:24 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-19 11:44:24 +0100 |
commit | 2a3de2c38c7b77adbc2c83e0245c15dbba3b6edb (patch) | |
tree | 46f5926503fb91157abe1b22f111bcacf6251b2f /src/main/java/at | |
parent | 4a40d28e06975dc258ce14078e98800ea140cd97 (diff) | |
download | skyhanni-2a3de2c38c7b77adbc2c83e0245c15dbba3b6edb.tar.gz skyhanni-2a3de2c38c7b77adbc2c83e0245c15dbba3b6edb.tar.bz2 skyhanni-2a3de2c38c7b77adbc2c83e0245c15dbba3b6edb.zip |
Added support for extra data in error manager.
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt | 47 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 17 |
2 files changed, 52 insertions, 12 deletions
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 a954f572d..277452f5a 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -47,16 +47,25 @@ object ErrorManager { } ?: "Error id not found!") } + @Deprecated("Use data as well", ReplaceWith("logErrorStateWithData()")) fun logErrorState(userMessage: String, internalMessage: String) { - logError(IllegalStateException(internalMessage), userMessage) + logError(IllegalStateException(internalMessage), userMessage, false) } - // we love java - fun logError(throwable: Throwable, message: String) { - logError(throwable, message, false) + fun logErrorStateWithData(userMessage: String, internalMessage: String, vararg extraData: Pair<String, Any?>) { + logError(IllegalStateException(internalMessage), userMessage, false, *extraData) } - fun logError(throwable: Throwable, message: String, ignoreErrorCache: Boolean) { + fun logError(throwable: Throwable, message: String, vararg extraData: Pair<String, Any?>) { + logError(throwable, message, false, *extraData) + } + + fun logError( + throwable: Throwable, + message: String, + ignoreErrorCache: Boolean, + vararg extraData: Pair<String, Any?> + ) { val error = Error(message, throwable) error.printStackTrace() Minecraft.getMinecraft().thePlayer ?: return @@ -73,10 +82,12 @@ object ErrorManager { val stackTrace = throwable.getCustomStackTrace(false).joinToString("\n").removeSpam() val randomId = UUID.randomUUID().toString() + val extraDataString = buildExtraDataString(extraData) val rawMessage = message.removeColor() - errorMessages[randomId] = "```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n \n$stackTrace\n```" + errorMessages[randomId] = + "```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n \n$stackTrace\n$extraDataString```" fullErrorMessages[randomId] = - "```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n(full stack trace)\n \n$fullStackTrace\n```" + "```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n(full stack trace)\n \n$fullStackTrace\n$extraDataString```" LorenzUtils.clickableChat( "§c[SkyHanni-${SkyHanniMod.version}]: $message§c. Click here to copy the error into the clipboard.", @@ -84,6 +95,28 @@ object ErrorManager { false ) } + + private fun buildExtraDataString(extraData: Array<out Pair<String, Any?>>): String { + val extraDataString = if (extraData.isNotEmpty()) { + val builder = StringBuilder() + for ((key, value) in extraData) { + builder.append(key) + builder.append(": ") + if (value is Iterable<*>) { + builder.append("\n") + for (line in value) { + builder.append(" - '$line'") + builder.append("\n") + } + } else { + builder.append("'$value'") + } + builder.append("\n") + } + "\nExtra data:\n$builder" + } else "" + return extraDataString + } } private fun Throwable.getCustomStackTrace(full: Boolean, parent: List<String> = emptyList()): List<String> = buildList { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 205726743..a1b7ed09f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -220,9 +220,13 @@ object ItemUtils { val rarity = LorenzRarity.readItemRarity(this) data.itemRarity = rarity if (rarity == null && logError) { - ErrorManager.logErrorState( + ErrorManager.logErrorStateWithData( "Could not read rarity for item $name", - "getItemRarityOrNull not found for: $internalName, name:'$name''" + "Failed to read rarity from item rarity via item lore", + "internal name" to internalName, + "item name" to name, + "inventory name" to InventoryUtils.openInventoryName(), + "lore" to getLore(), ) } return rarity @@ -302,15 +306,18 @@ object ItemUtils { return getItemStack().nameWithEnchantment ?: error("Could not find item name for $this") } - private fun getPetRarity(pet: ItemStack): LorenzRarity? { val rarityId = pet.getInternalName().asString().split(";").last().toInt() val rarity = LorenzRarity.getById(rarityId) val name = pet.name if (rarity == null) { - ErrorManager.logErrorState( + ErrorManager.logErrorStateWithData( "Could not read rarity for pet $name", - "getPetRarity not found for: ${pet.getInternalName()}, name:'$name'" + "Failed to read rarity from pet item via internal name", + "internal name" to pet.getInternalName(), + "item name" to name, + "rarity id" to rarityId, + "inventory name" to InventoryUtils.openInventoryName() ) } return rarity |