HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
439 stars 77 forks source link

Character encoding issues when compiling resources files into library #55

Closed imeckler closed 10 years ago

imeckler commented 10 years ago

I get the following compilation failure when building both from the latest version on github and the latest hackage version:

src/Graphics/UI/Threepenny/Internal/Resources.hs:15:7:
    Exception when trying to run compile-time code:
      src/Graphics/UI/jquery.js: hGetContents: invalid argument (invalid byte sequence)
      Code: Language.Haskell.TH.Quote.quoteExp
              include "Graphics/UI/jquery.js"
HeinrichApfelmus commented 10 years ago

Looks like there's an issue with the current directory and Template Haskell. What version of cabal and GHC are you using?

duplode commented 10 years ago

This looks like an encoding issue. In Linux, I can reproduce the error with:

env LC_CTYPE=latin1 cabal build

What is your OS? Further investigation will likely be OS-specific (unfortunately I don't have a Windows system around to test it right now).

imeckler commented 10 years ago

Ghc version: 7.6.3 Cabal:

cabal-install version 1.18.0.1
using version 1.18.1 of the Cabal library 

/etc/lsb-release:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10"

LC_CTYPE isn't set in my environment.

duplode commented 10 years ago

LC_CTYPE isn't set in my environment.

Then it is probably LANG which specifies it. Here I have...

$ printenv | grep UTF-8
LANG=en_US.UTF-8

...and this...

$ env LANG=en.US.latin1 cabal build

...reproduces the error as well.

imeckler commented 10 years ago

Strange, I have LANG=en_US.UTF-8 in my env.

imeckler commented 10 years ago

In ghci:

Prelude System.IO> openFile "src/Graphics/UI/jquery.js" ReadMode >>= hGetContents >>= putStr
[elided output]
,e.browser.version=z.version),e.browser.webkit&&(e.browser.safari=!0),j.test("*** Exception: src/Graphics/UI/jquery.js: hGetContents: invalid argument (invalid byte sequence)

I should add that reading the contents of a few other files worked fine. I'm going to try replacing the file with jQuery downloaded directly from their site. (EDIT: That did nothing).

imeckler commented 10 years ago

It worked when I manually set the encoding on the handle as follows:

Prelude System.IO> h <- openFile "src/Graphics/UI/jquery.js" ReadMode
Prelude System.IO> hSetEncoding h utf8

Not sure why my system locale is set incorrectly. Thanks though.

HeinrichApfelmus commented 10 years ago

Does the latest commit on the development branch help?

imeckler commented 10 years ago

It didn't, but I fixed my locale issues by running

locale-gen en_US en_US.UTF-8
dpkg-reconfigure locales

and threepenny built successfully afterward.

duplode commented 10 years ago

I'm not certain about how well my experiment reproduces the original issue; in any case, env LANG=en_US.latin1 cabal build now works.

HeinrichApfelmus commented 10 years ago

@duplode Ok, so the source level fix works to some extend. Thanks!