From a20e3696ece23ba4389deeebf63e1cc33f717705 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 13 Feb 2024 16:35:10 +0100 Subject: Hide repeated error messages in logs --- src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt | 11 +++++++++-- .../firmament/features/texturepack/CustomSkyBlockTextures.kt | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt b/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt index 9bdcc26..8a7b387 100644 --- a/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt +++ b/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt @@ -16,7 +16,10 @@ import moe.nea.firmament.Firmament * Subscriptions may not necessarily be delivered in the order of registering. */ open class FirmamentEventBus { - data class Handler(val invocation: (T) -> Unit, val receivesCancelled: Boolean) + data class Handler( + val invocation: (T) -> Unit, val receivesCancelled: Boolean, + var knownErrors: MutableSet> = mutableSetOf(), + ) private val toHandle: MutableList> = CopyOnWriteArrayList() fun subscribe(handle: (T) -> Unit) { @@ -33,7 +36,11 @@ open class FirmamentEventBus { try { function.invocation(event) } catch (e: Exception) { - Firmament.logger.error("Caught exception during processing event $event by $function", e) + val klass = e.javaClass + if (!function.knownErrors.contains(klass) || Firmament.DEBUG) { + function.knownErrors.add(klass) + Firmament.logger.error("Caught exception during processing event $event by $function", e) + } } } } diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt index d925d6e..f363878 100644 --- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt +++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt @@ -44,6 +44,7 @@ object CustomSkyBlockTextures : FirmamentFeature { it.overrideModel = ModelIdentifier("firmskyblock", id.identifier.path, "inventory") } TickEvent.subscribe { + throw RuntimeException() if (TConfig.cacheDuration < 1 || it.tickCount % TConfig.cacheDuration == 0) { CustomItemModelEvent.clearCache() skullTextureCache.clear() -- cgit