diff options
3 files changed, 36 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt index df19aac2e..363cbfd7c 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt @@ -126,17 +126,19 @@ class RepoManager(private val configLocation: File) { ErrorManager.resetCache() Minecraft.getMinecraft().addScheduledTask { error = false - RepositoryReloadEvent(repoLocation, gson).postAndCatchAndBlock(true, true) { - LorenzUtils.clickableChat( - "§e[SkyHanni] Error with the repo detected, try /shupdaterepo to fix it!", - "shupdaterepo" - ) + RepositoryReloadEvent(repoLocation, gson).postAndCatchAndBlock(ignoreErrorCache = true) { error = true } comp.complete(null) if (answerMessage.isNotEmpty() && !error) { LorenzUtils.chat("§e[SkyHanni] §a$answerMessage") } + if (error) { + LorenzUtils.clickableChat( + "§e[SkyHanni] Error with the repo detected, try /shupdaterepo to fix it!", + "shupdaterepo" + ) + } } return comp } diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt index e4e6f87c5..2f39e381d 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.events import at.hannibal2.skyhanni.mixins.transformers.AccessorEventBus import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.Event import net.minecraftforge.fml.common.eventhandler.IEventListener @@ -16,24 +17,31 @@ abstract class LorenzEvent : Event() { fun postAndCatchAndBlock( printError: Boolean = true, - stopOnError: Boolean = false, + stopOnFirstError: Boolean = false, + ignoreErrorCache: Boolean = false, onError: (Throwable) -> Unit, ): Boolean { + val visibleErrors = 3 + var errors = 0 for (listener in getListeners()) { try { listener.invoke(this) - } catch (e: Throwable) { - if (printError) { + } catch (throwable: Throwable) { + errors++ + if (printError && errors <= visibleErrors) { val callerName = listener.toString().split(" ")[1].split("@")[0].split(".").last() - ErrorManager.logError( - e, - "Caught an ${e::class.simpleName ?: "error"} at $eventName in $callerName: '${e.message}'" - ) + val errorName = throwable::class.simpleName ?: "error" + val message = "Caught an $errorName at $eventName in $callerName: '${throwable.message}'" + ErrorManager.logError(throwable, message, ignoreErrorCache) } - onError(e) - if (stopOnError) break + onError(throwable) + if (stopOnFirstError) break } } + if (errors > visibleErrors) { + val hiddenErrors = errors - visibleErrors + LorenzUtils.chat("§c[SkyHanni] $hiddenErrors more errors in $eventName are hidden!") + } return if (isCancelable) isCanceled else false } 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 7db251300..84b180cd8 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -51,16 +51,23 @@ object ErrorManager { logError(IllegalStateException(internalMessage), userMessage) } + // we love java fun logError(throwable: Throwable, message: String) { + logError(throwable, message, false) + } + + fun logError(throwable: Throwable, message: String, ignoreErrorCache: Boolean) { val error = Error(message, throwable) Minecraft.getMinecraft().thePlayer ?: throw error error.printStackTrace() - val pair = if (throwable.stackTrace.isNotEmpty()) { - throwable.stackTrace[0].let { it.fileName to it.lineNumber } - } else message to 0 - if (cache.getIfPresent(pair) != null) return - cache.put(pair, Unit) + if (!ignoreErrorCache) { + val pair = if (throwable.stackTrace.isNotEmpty()) { + throwable.stackTrace[0].let { it.fileName to it.lineNumber } + } else message to 0 + if (cache.getIfPresent(pair) != null) return + cache.put(pair, Unit) + } val fullStackTrace = throwable.getExactStackTrace(true).joinToString("\n") val stackTrace = throwable.getExactStackTrace(false).joinToString("\n").removeSpam() |