Skip to content

Commit

Permalink
Track overall position in error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed Oct 18, 2023
1 parent 9be9534 commit 81ddcd5
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 @@ -140,16 +140,18 @@ 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) 0
readEvents' header = go (decodeEvents header) 0 0 0
where
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
go :: Decoder Event -> Word64 -> Word64 -> Word64 -> BL.ByteString -> [Either String Event]
go decoder !last_chunk_sz !bytes_consumed !event_n bytes = case decoder of
Produce event decoder' -> Right event : go decoder' last_chunk_sz bytes_consumed (event_n+1) bytes
Consume k -> case bytes of
BL.Empty -> []
BL.Chunk chunk chunks -> go (k chunk) event_n chunks
BL.Chunk chunk chunks -> go (k chunk) (fromIntegral $ B.length chunk) (bytes_consumed + last_chunk_sz) event_n chunks
Done {} -> []
Error _ err -> [Left $ "in event " ++ show event_n ++ ": " ++ err]
Error leftovers err ->
let pos = bytes_consumed + last_chunk_sz - fromIntegral (B.length leftovers)
in [Left $ concat [ "in event ", show event_n, " @ offset ", show pos, ": ", 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 81ddcd5

Please sign in to comment.