From 5b1ecbde01591fef7928992adced759ba75249d8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 28 Oct 2026 18:46:53 -0500 Subject: prevent event bus malfunction with Event type --- src/slskd/Events/EventBus.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/slskd') 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 data) where T : Event { + // we look up the list of subscribers using T, and then cast the callback to Func, 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 -- cgit v1.2.3