How does GHC avoid "<stderr>: hPutChar: invalid argument (invalid character)"?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How does GHC avoid "<stderr>: hPutChar: invalid argument (invalid character)"?

Yuji Yamamoto

Hello Haskellers,

Currently, I’m working on this issue,
where haddock crashes when printing the Unicode “bullet character” 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!


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How does GHC avoid "<stderr>: hPutChar: invalid argument (invalid character)"?

Brandon Allbery
On Mon, Apr 10, 2017 at 7:24 PM, Yuji Yamamoto <[hidden email]> wrote:

Currently, I’m working on this issue,

where haddock crashes when printing the Unicode “bullet character” 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.


--
brandon s allbery kf8nh                               sine nomine associates
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How does GHC avoid "<stderr>: hPutChar: invalid argument (invalid character)"?

Merijn Verstraaten
In reply to this post by Yuji Yamamoto
This sounds to me like a classical case of a wrongly (or not) configured locale/terminal. As a starting point I would check both what the locale variables are set to (run "locale" in the shell) and check what encoding the terminal is set to. I've noticed a lot of linux installs have completely borked configuration with regards to these and in those cases GHC can't do much.

Side note: Just forcing output to be utf8 is *definitely* the wrong thing to do, as it'd break any environment set to a different encoding...

Cheers,
Merijn

> On 11 Apr 2017, at 1:24, Yuji Yamamoto <[hidden email]> wrote:
>
> Hello Haskellers,
>
> Currently, I’m working on this issue,
> where haddock crashes when printing the Unicode “bullet character” 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!
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How does GHC avoid "<stderr>: hPutChar: invalid argument (invalid character)"?

Yuji Yamamoto
Brandon and Merijn,

Thank you for advice.
But I should have noted that the issue is about Windows...
So things to take care might be different...

2017-04-11 16:46 GMT+09:00 Merijn Verstraaten <[hidden email]>:
This sounds to me like a classical case of a wrongly (or not) configured locale/terminal. As a starting point I would check both what the locale variables are set to (run "locale" in the shell) and check what encoding the terminal is set to. I've noticed a lot of linux installs have completely borked configuration with regards to these and in those cases GHC can't do much.

Side note: Just forcing output to be utf8 is *definitely* the wrong thing to do, as it'd break any environment set to a different encoding...

Cheers,
Merijn

> On 11 Apr 2017, at 1:24, Yuji Yamamoto <[hidden email]> wrote:
>
> Hello Haskellers,
>
> Currently, I’m working on this issue,
> where haddock crashes when printing the Unicode “bullet character” 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!
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.




--

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Loading...