Skip to content

Commit cb665d0

Browse files
committed
trace-froward: better handle the error cases
1 parent 3515f49 commit cb665d0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

trace-forward/src/Trace/Forward/Utils/TraceObject.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,15 @@ readFromSink ForwardSink{forwardQueue} =
8383
res <- atomically $ readFromSinkSTM forwardQueue blocking n
8484
pure $ case blocking of
8585
TokNonBlocking -> NonBlockingReply res
86-
TokBlocking -> BlockingReply $ case NE.nonEmpty res of
87-
-- If `n == 0` ?????
88-
Nothing -> error "impossible"
89-
(Just ne) -> ne
86+
TokBlocking -> BlockingReply $
87+
-- Convert to a non-empty list.
88+
case NE.nonEmpty res of
89+
(Just ne) -> ne
90+
Nothing -> if n > 0
91+
then error "impossible"
92+
-- I can't help returning zero
93+
-- items in a non-empty list.
94+
else error "Good luck!"
9095
, Forwarder.recvMsgDone = return ()
9196
}
9297

0 commit comments

Comments
 (0)