Table of Contents

CHR0012: Event types should avoid nullable properties

Rule Description

Event types can contain nullable properties, but this is often an anti-pattern in event sourcing. A nullable field can hide multiple meanings in one event. Prefer expressing optional facts with a dedicated event type when possible.

Severity

Warning

Example

Warning

using Cratis.Chronicle.Events;

[EventType]
public record MissionAccepted(
    string MissionId,
    DateOnly? StartDate);

Preferred

using Cratis.Chronicle.Events;

[EventType]
public record MissionAccepted(
    string MissionId,
    DateOnly StartDate);

[EventType]
public record MissionAcceptedWithoutStartDate(
    string MissionId);

Why This Rule Exists

Events represent immutable facts. Nullable properties can blur the meaning of those facts and force consumers to branch on missing values.

Keeping event types explicit:

  • improves readability
  • reduces ambiguity for projections, reducers, and reactors
  • keeps event history easier to understand
  • CHR0001: Event sequence append operations