aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt47
5 files changed, 40 insertions, 22 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index b36d04121..b0a43cb05 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -85,7 +85,7 @@ object Commands {
registerCommand("shcopyparticles") { CopyNearbyParticlesCommand.command(it) }
registerCommand("shtestpacket") { PacketTest.toggle() }
registerCommand("shtestmessage") { TestChatCommand.command(it) }
- registerCommand("shcopyerror") { CopyErrorCommand.command() }
+ registerCommand("shcopyerror") { CopyErrorCommand.command(it) }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
index 57410df5d..08234bdf1 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
@@ -1,6 +1,6 @@
package at.hannibal2.skyhanni.events
-import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.test.command.CopyErrorCommand
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.eventhandler.Event
@@ -19,7 +19,7 @@ abstract class LorenzEvent : Event() {
LorenzUtils.chat("§c[SkyHanni] You need to use a newer version of NotEnoughUpdates (alpha-11 or newer)! If you need help downloading it, go to the skyhanni discord.")
} else {
it.printStackTrace()
- LorenzUtils.chat("§cSkyHanni ${SkyHanniMod.version} caught and logged an ${it::class.simpleName ?: "error"} at ${eventName}: ${it.message}")
+ CopyErrorCommand.logError(it, "Caught an ${it::class.simpleName ?: "error"} at ${eventName}: '${it.message}'")
}
}.getOrDefault(isCanceled)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
index cc04a303b..f1b1a0db3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
@@ -8,7 +8,6 @@ import at.hannibal2.skyhanni.events.PreProfileSwitchEvent
import at.hannibal2.skyhanni.events.VisitorArrivalEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.test.command.CopyErrorCommand
-import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
@@ -53,9 +52,7 @@ class GardenVisitorTimer {
try {
updateVisitorDisplay()
} catch (error: Throwable) {
- CopyErrorCommand.errorMessage = error.toString()
- CopyErrorCommand.errorStackTrace = error.stackTrace.asList()
- LorenzUtils.chat("§c[SkyHanni] encountered an error when updating visitor display, please run /shcopyerror")
+ CopyErrorCommand.logError(error, "Encountered an error when updating visitor display")
}
try {
GardenVisitorDropStatistics.saveAndUpdate()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt
index 05a4cd017..10c1f1fa1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt
@@ -59,9 +59,7 @@ class TrevorFeatures {
TrevorSolver.findMob()
}
} catch (error: Throwable) {
- CopyErrorCommand.errorMessage = error.toString()
- CopyErrorCommand.errorStackTrace = error.stackTrace.asList()
- LorenzUtils.chat("§c[SkyHanni] encountered an error when updating the trapper solver, please run /shcopyerror")
+ CopyErrorCommand.logError(error, "Encountered an error when updating the trapper solver")
}
}
}
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 e2fbd98c5..6820deba7 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt
@@ -1,21 +1,44 @@
package at.hannibal2.skyhanni.test.command
+import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
+import com.google.common.cache.CacheBuilder
+import java.util.*
+import java.util.concurrent.TimeUnit
object CopyErrorCommand {
- var errorMessage = ""
- var errorStackTrace = listOf<StackTraceElement>()
- fun command() {
- try {
- if (errorMessage == "") LorenzUtils.chat("§c[SkyHanni] no error to copy") else {
- val result = errorMessage + "\nCaused at:\n" + errorStackTrace.joinToString("\n")
- OSUtils.copyToClipboard(result)
- LorenzUtils.chat("§e[SkyHanni] error message copied into the clipboard, please report it on the SkyHanni discord!")
- }
- } catch (error: Throwable) {
- OSUtils.copyToClipboard(error.toString())
- LorenzUtils.chat("§c[SkyHanni] error occurred while fetching error, please report this on the SkyHanni discord!")
+ // random id -> error message
+ private val errorMessages = mutableMapOf<String, String>()
+ private var cache =
+ CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build<Pair<String, Int>, Unit>()
+
+ fun command(array: Array<String>) {
+ if (array.size != 1) {
+ LorenzUtils.chat("§cUse /shcopyerror <error id>")
+
+ return
}
+
+ LorenzUtils.chat(errorMessages[array[0]]?.let {
+ OSUtils.copyToClipboard(it)
+ "§e[SkyHanni] Error copied into the clipboard, please report it on the SkyHanni discord!"
+ } ?: "§c[SkyHanni] Error id not found!")
+ }
+
+ fun logError(error: Throwable, message: String) {
+ val pair = error.stackTrace[0].let { it.fileName to it.lineNumber }
+ if (cache.getIfPresent(pair) != null) return
+ cache.put(pair, Unit)
+
+ val errorMessage = error.toString()
+ val stackTrace = error.stackTrace.asList().joinToString("\n")
+ val randomId = UUID.randomUUID().toString()
+ errorMessages[randomId] = "```$errorMessage\nCaused at:\n$stackTrace```"
+
+ LorenzUtils.clickableChat(
+ "§cSkyHanni ${SkyHanniMod.version} $message. Click here to copy the error into the clipboard.",
+ "shcopyerror $randomId"
+ )
}
} \ No newline at end of file