Skip to content

Commit

Permalink
Report event number in error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed Oct 18, 2023
1 parent 878d2a6 commit 9be9534
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/GHC/RTS/Events/Incremental.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ module GHC.RTS.Events.Incremental
, readEventLog
, readEventLogOrFail
) where

import Control.Monad
import Data.Either
import Data.Maybe
import Data.Word
import Prelude

import qualified Data.Binary.Get as G
Expand Down Expand Up @@ -138,16 +140,16 @@ readEvents header = f . break isLeft . readEvents' header
-- Note that it doesn't fail if it consumes all input in the middle of decoding
-- of an event.
readEvents' :: Header -> BL.ByteString -> [Either String Event]
readEvents' header = go (decodeEvents header)
readEvents' header = go (decodeEvents header) 0
where
go :: Decoder Event -> BL.ByteString -> [Either String Event]
go decoder bytes = case decoder of
Produce event decoder' -> Right event : go decoder' bytes
go :: Decoder Event -> Word64 -> BL.ByteString -> [Either String Event]
go decoder !event_n bytes = case decoder of
Produce event decoder' -> Right event : go decoder' (event_n+1) bytes
Consume k -> case bytes of
BL.Empty -> []
BL.Chunk chunk chunks -> go (k chunk) chunks
BL.Chunk chunk chunks -> go (k chunk) event_n chunks
Done {} -> []
Error _ err -> [Left err]
Error _ err -> [Left $ "in event " ++ show event_n ++ ": " ++ err]

-- | Read an entire event log from a lazy bytestring. It returns an error message if it
-- encounters an error while decoding.
Expand Down

0 comments on commit 9be9534

Please sign in to comment.