haskell / ghc-events

Library and tool for parsing .eventlog files from GHC
http://www.haskell.org/haskellwiki/ThreadScope
Other
33 stars 33 forks source link

UserBinaryMessage containing non utf8 text leads to runtime error #90

Closed TeofilC closed 1 year ago

TeofilC commented 2 years ago

The logic for printing UserBinaryMessages assumes that the payload is utf8 encoded. Non-utf8 encoded payloads, like those produced by programs that use the opentelemetry library, will lead to a runtime error.

You can reproduce this by running the following to produce an eventlog:

module Main where

import Debug.Trace.Binary
import Data.ByteString

main :: IO ()
main = traceBinaryEventIO (pack [0x0080])

and then when you load this into ghc-events you will get output like the following:

> ghc-events inc repro.eventlog 
93401: cap 0: creating thread 1
94801: cap 0: running thread 1
102801: cap 0: stopping thread 1 (making a foreign call)
103101: cap 0: running thread 1
ghc-events: user error (Cannot decode byte '\x80': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream)

Threadscope will also crash when showing relevant events.

I'll try to fix this. I feel like if we fail to decode as utf8 then we should have some sort of fallback format like base64 rather than throwing an error. Or perhaps we can just use decodeUtf8Lenient

Mikolaj commented 2 years ago

That sounds very reasonable (both ways).