[Haskell-cafe] How does GHC avoid "<stderr>: hPutChar: invalid argument (invalid character)"?

Yuji Yamamoto whosekiteneverfly at gmail.com
Mon Apr 10 23:24:55 UTC 2017


Hello Haskellers,

Currently, I’m working on this issue
<https://github.com/haskell/haddock/pull/566>,
where haddock crashes when printing the Unicode “bullet character”
<http://www.fileformat.info/info/unicode/char/2022/index.htm> on stderr
whose character encoding is not UTF-8.

In the beforementioned pull request, I just added hSetEncoding stderr utf8
as a quick-and-dirty workaround.
But GHC actually doesn’t do so: GHC prints “?” instead of the bullet
character when stderr is not Unicode-compatible.

So, I believe there’s a better way to handle the case, and GHC knows it.
Then, how does GHC detect the handle’s character encoding and convert
incompatible characters (such as the bullet character) into “?” to avoid
the error?
I couldn’t get it by reading the source of GHC a bit.

Thanks in advance!
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170411/cc50a147/attachment.html>


More information about the Haskell-Cafe mailing list