aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/test/command
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-18 15:41:09 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-18 15:41:09 +0200
commit792e103664e2a59b0e5c710582ad98cae4bb7a42 (patch)
tree56587277bcfee7f59e6c8a03fa24f9d50593d045 /src/main/java/at/hannibal2/skyhanni/test/command
parentbb6a64dadca09ac84feedda1923854f9482df455 (diff)
downloadskyhanni-792e103664e2a59b0e5c710582ad98cae4bb7a42.tar.gz
skyhanni-792e103664e2a59b0e5c710582ad98cae4bb7a42.tar.bz2
skyhanni-792e103664e2a59b0e5c710582ad98cae4bb7a42.zip
Reworked clickable error messages and added support for all custom event errors
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test/command')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt47
1 files changed, 35 insertions, 12 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 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