[Haskell-cafe] hGetContents Illegal byte sequence / ghc-pkg

Brent Yorgey byorgey at seas.upenn.edu
Sat Aug 11 15:53:19 CEST 2012


On Sat, Aug 11, 2012 at 12:13:45PM +0100, Benjamin Edwards wrote:
> Hello café,
> 
> I have a program that is crashing, and I have no idea why:
> 
> module Main
>   where
> 
> import System.Process (readProcessWithExitCode)
> 
> 
> main :: IO ()
> main = do _ <- readProcessWithExitCode "ghc-pkg" ["describe", "hoopl"] ""
>           putStrLn "Should never get here"
> 
> this is using the process package from hackage. The program crashes with
> 
> minimal-test: fd:5: hGetContents: invalid argument (invalid byte sequence)
> minimal-test: thread blocked indefinitely in an MVar operation
> 
> inspecting the source of readProcessWithExitCode yields an obvious
> explanation to the MVar problem, but I don't understand why hGetContents is
> so offended.

The 'invalid argument' error from hGetContents indicates that a wrong
encoding is being assumed.  I don't know enough about how
putStr/hGetContents decide on an encoding, but in any case it works
for me (that is, it prints "Should never get here").  The likely
sticking point is that one of the authors of hoopl, João Dias, has a
name which contains U+00E3: LATIN SMALL LETTER A WITH TILDE.

Try doing  

  ghc-pkg describe hoopl > hoopl.txt
  file hoopl.txt

to get an indication of what encoding is being used, or manually take
a look at the bytes being generated using

  ghc-pkg describe hoopl | hexdump -C

I don't know what the solution is but at least this should give some
additional information.

-Brent



More information about the Haskell-Cafe mailing list