diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-10-21 12:01:47 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-10-21 12:01:47 +0200 |
commit | a98927303854058ad2d7a0d8bb88265c54139614 (patch) | |
tree | eae66388dfbc7e736fdc43a8d501edb457e61b5b /src/main/java/at/hannibal2/skyhanni/events | |
parent | 830fdb7022ac173b421daeddfbc7e67c0d9f891b (diff) | |
download | skyhanni-a98927303854058ad2d7a0d8bb88265c54139614.tar.gz skyhanni-a98927303854058ad2d7a0d8bb88265c54139614.tar.bz2 skyhanni-a98927303854058ad2d7a0d8bb88265c54139614.zip |
better repo error handling
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/events')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt | 26 |
1 files changed, 17 insertions, 9 deletions
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 } |