Skip to content

Commit e47dd33

Browse files
committed
Add support for processing SystemEvent with exception handling in BroadcastEventStreamProcessor
1 parent 34e46d7 commit e47dd33

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

krescent-core/src/main/kotlin/dev/helight/krescent/event/processor/BroadcastEventStreamProcessor.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@ package dev.helight.krescent.event.processor
33
import dev.helight.krescent.HandlerChainParticipant
44
import dev.helight.krescent.event.Event
55
import dev.helight.krescent.event.EventStreamProcessor
6+
import dev.helight.krescent.event.SystemEvent
67
import java.util.function.Consumer
78

89
class BroadcastEventStreamProcessor(
910
private val processors: List<EventStreamProcessor>,
1011
) : EventStreamProcessor {
12+
1113
override suspend fun process(event: Event) {
12-
for (processor in processors) {
13-
processor.process(event)
14+
if (event is SystemEvent) {
15+
val exceptions = mutableListOf<Exception>()
16+
for (processor in processors) {
17+
try {
18+
processor.process(event)
19+
} catch (ex: Exception) {
20+
exceptions.add(ex)
21+
}
22+
}
23+
if (exceptions.isNotEmpty()) throw SystemEventException(exceptions)
24+
} else {
25+
for (processor in processors) {
26+
processor.process(event)
27+
}
1428
}
1529
}
1630

@@ -20,4 +34,8 @@ class BroadcastEventStreamProcessor(
2034
processor.accept(visitor)
2135
}
2236
}
37+
38+
class SystemEventException(
39+
val exceptions: List<Exception>,
40+
) : Exception("Exceptions have occurred while processing a system event: ${exceptions.map { it.message }}")
2341
}

0 commit comments

Comments
 (0)