From 57403965ea3f7e9534299621085a7848f9667318 Mon Sep 17 00:00:00 2001 From: Chris Condron Date: Thu, 19 Dec 2024 16:31:42 -0500 Subject: [PATCH] Ensure reads match listeners on missing stream handling --- .../StreamStore/StreamReader.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ReactiveDomain.Foundation/StreamStore/StreamReader.cs b/src/ReactiveDomain.Foundation/StreamStore/StreamReader.cs index ec9eb525..3020ad2a 100644 --- a/src/ReactiveDomain.Foundation/StreamStore/StreamReader.cs +++ b/src/ReactiveDomain.Foundation/StreamStore/StreamReader.cs @@ -151,9 +151,9 @@ public virtual bool Read( Ensure.Nonnegative((long)checkpoint, nameof(checkpoint)); if (count != null) Ensure.Positive((long)count, nameof(count)); - if (!ValidateStreamName(streamName)) - throw new ArgumentException("Stream not found.", streamName); - + if (!ValidateStreamName(streamName)) + return false; + _cancelled = false; FirstEventRead = false; StreamName = streamName; @@ -191,8 +191,17 @@ public virtual bool Read( /// The stream name to validate. public bool ValidateStreamName(string streamName) { - var currentSlice = _streamStoreConnection.ReadStreamForward(streamName, 0, 1); - return !(currentSlice is StreamDeletedSlice); + try + { + var result = _streamStoreConnection.ReadStreamForward(streamName, 0, 1); + + return result.GetType() == typeof(StreamEventsSlice); + } + catch (Exception) + { + return false; + } + } protected virtual void EventRead(RecordedEvent recordedEvent)