diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-10-28 18:46:53 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-10-28 18:46:53 -0500 |
| commit | 5b1ecbde01591fef7928992adced759ba75249d8 (patch) | |
| tree | b82d78b217f925f777e67bc2fd51022cdc273aa1 /src/slskd | |
| parent | fe97cb3fcbfaf66374ea09527672a9444d3ef1da (diff) | |
| download | slskd-5b1ecbde01591fef7928992adced759ba75249d8.tar.gz | |
prevent event bus malfunction with Event type
Diffstat (limited to 'src/slskd')
| -rw-r--r-- | src/slskd/Events/EventBus.cs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/slskd/Events/EventBus.cs b/src/slskd/Events/EventBus.cs index 0c9b8e57..72f797ff 100644 --- a/src/slskd/Events/EventBus.cs +++ b/src/slskd/Events/EventBus.cs @@ -88,6 +88,15 @@ public class EventBus public virtual void Raise<T>(T data) where T : Event { + // we look up the list of subscribers using T, and then cast the callback to Func<T, Task>, and this breaks when + // T is Event rather than the derived type. the fix for this involves wrapping the callbacks with another delegate + // that performs the proper cast (or just rethinking this approach entirely), so we're just going to throw + // at run-time instead, which the smallest amount of functional testing will surface + if (typeof(T) == typeof(Event)) + { + throw new ArgumentException($"Raise can not be called with a type argument of type Event because the bus can't properly source the list of subscribers. Supply the derived Event Type when calling"); + } + Log.Debug("Handling {Type}: {Data}", typeof(T), data); // save the event to the database before broadcasting to consumers |
