aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-02-13 16:35:10 +0100
committerLinnea Gräf <nea@nea.moe>2024-02-13 16:35:10 +0100
commita20e3696ece23ba4389deeebf63e1cc33f717705 (patch)
tree166e28cd8dfea67967ccc521afc115fd47993931 /src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt
parented9b49c8a3ac76051f04037e4ae1ac760ba8d8c9 (diff)
downloadfirmament-a20e3696ece23ba4389deeebf63e1cc33f717705.tar.gz
firmament-a20e3696ece23ba4389deeebf63e1cc33f717705.tar.bz2
firmament-a20e3696ece23ba4389deeebf63e1cc33f717705.zip
Hide repeated error messages in logs
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt11
1 files changed, 9 insertions, 2 deletions
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<T : FirmamentEvent> {
- data class Handler<T>(val invocation: (T) -> Unit, val receivesCancelled: Boolean)
+ data class Handler<T>(
+ val invocation: (T) -> Unit, val receivesCancelled: Boolean,
+ var knownErrors: MutableSet<Class<*>> = mutableSetOf(),
+ )
private val toHandle: MutableList<Handler<T>> = CopyOnWriteArrayList()
fun subscribe(handle: (T) -> Unit) {
@@ -33,7 +36,11 @@ open class FirmamentEventBus<T : FirmamentEvent> {
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)
+ }
}
}
}