CHR0055: Unknown event stream on typed event source filter
Rule description
Section titled “Rule description”[FromEventSource<TSource>("stream")] makes a reactor or reducer handle only the events of one stream of an event source definition. The stream name must be one that TSource declares with [EventStream]. If it is not, the client throws EventStreamDoesNotBelongToEventSource when it registers the observer, so the application fails at start up.
CHR0055 reports the same mistake when you compile. The names are compared exactly, including the casing.
Severity
Section titled “Severity”Error
Example
Section titled “Example”using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSources;using Cratis.Chronicle.Reactors;
[EventType]public record Chr0055PaymentReceived(decimal Amount);
[EventSource("Order")][EventStream("Payments")]public class Chr0055OrderEventSource : IEventSource;
// Error CHR0055: Chr0055OrderEventSource does not declare an event stream named "Payment".[FromEventSource<Chr0055OrderEventSource>("Payment")]public class Chr0055PaymentReactor : IReactor{ public Task Received(Chr0055PaymentReceived @event, EventContext context) => Task.CompletedTask;}How to fix
Section titled “How to fix”Use the name of a declared stream, or declare the stream on the definition.
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSources;using Cratis.Chronicle.Reactors;
[EventType]public record Chr0055FixPaymentReceived(decimal Amount);
[EventSource("Order")][EventStream("Payments")]public class Chr0055FixOrderEventSource : IEventSource;
// The stream name matches the declared stream exactly.[FromEventSource<Chr0055FixOrderEventSource>("Payments")]public class Chr0055FixPaymentReactor : IReactor{ public Task Received(Chr0055FixPaymentReceived @event, EventContext context) => Task.CompletedTask;}Why this rule exists
Section titled “Why this rule exists”The stream name is a string in an attribute argument, so the compiler cannot check it. Without the rule a typo ships and surfaces as a crash at start up. The rule moves the failure to the line that has the typo.
Related topics
Section titled “Related topics”- Filter observers by event source and stream
- Define an event source
- CHR0056: explicit routing contradicts a typed event source filter.
- Dynamic Consistency Boundary in Chronicle: streams are one of the dimensions a decision’s guard can narrow to.