Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildAndWatch fails because of locale / invalid byte sequence #249

Closed
andys8 opened this issue Feb 3, 2023 · 3 comments
Closed

buildAndWatch fails because of locale / invalid byte sequence #249

andys8 opened this issue Feb 3, 2023 · 3 comments

Comments

@andys8
Copy link
Contributor

andys8 commented Feb 3, 2023

Issue

/nix/store/2md452mq5labdcxlsc5gfik97dhxabbr-haskell-org-0.1.0.0
Removing _site...
Removing _cache...
Removing _cache/tmp...
Initialising...
  Creating store...
  Creating provider...
  Running rules...
Checking for out-of-date items
Compiling
  updated 2015-11-10-Haskell-Org-Board-Resolution.pdf
  [ERROR] _cache/a98f5fd1dec8ada591e76ae4112817f9 for Hakyll.Core.Resource.Provider.MetadataCache/community.markdown/body: Store.set: invalid argument (invalid byte sequence)

Related

System

I'm using OS: Manjaro 22.0.0 Sikaris, arch based.
Nix 2.8.1 installed as package manager, but not OS.

https://wiki.archlinux.org/title/locale

Locale

$ locale -a
C
C.UTF-8
de_DE.utf8
en_DE.utf8
en_US.utf8
POSIX

$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=
@andys8 andys8 changed the title buildAndWatch fails because of locale buildAndWatch fails because of locale / invalid byte sequence Feb 3, 2023
@TikhonJelvis
Copy link
Member

Thanks for the detailed error report! I'll take a look at this. Frankly, I've had too many headaches from locale settings with Haskell + Nix—on another project I ended up rewriting my Haskell code to always use UTF-8 regardless of the locale settings, so I'll try that here too. Not sure whether the same approach will work with Hakyll though.

@andys8
Copy link
Contributor Author

andys8 commented Feb 3, 2023

Sounds reasonable.

I think as long as there is this line (and maybe the others), passing an environment value from the outside is not possible as workaround.

export LC_ALL=C.UTF-8 # fix locale error with Hakyll (see #29)

Btw. dropping this line would make the project work with my system. Maybe LC_ALL in the two default.nix files is enough for Nix? I don't know.

TikhonJelvis added a commit that referenced this issue Feb 3, 2023
This change makes sure that the site executable *always* expects UTF-8, regardless of any locale environment variables. This should avoid problems like #29 and #249 in a more robust way than trying to set the right environment variables in `buildAndWatch` or `shell.nix`.

The diff ended up a bit noisy because of indentation changes; the key change was adding `Encoding.setLocaleEncoding Encoding.utf8` to the beginning of `main`.

I tested this by reproducing the Unicode error (using `nix-shell --pure`) and checking that the Haskell code change fixes the problem.
@TikhonJelvis
Copy link
Member

The annoying thing is that I added that line earlier because not having it was causing the same error on a different person's system :P. I hate dealing with differences in OS environments like this—so much incidental complexity, and hard to reasonably test to boot.

Hopefully #255 fixes this problem for everyone uniformly. It's more correct behavior anyhow: the site builder will always be building the contents of this repo, which are always in UTF-8, so that would be the right behavior even on a system that was explicitly not using UTF-8 by default. (Does anybody even seriously use systems like that any more? I legitimately don't know.)

TikhonJelvis added a commit that referenced this issue Feb 5, 2023
This change makes sure that the site executable *always* expects UTF-8, regardless of any locale environment variables. This should avoid problems like #29 and #249 in a more robust way than trying to set the right environment variables in `buildAndWatch` or `shell.nix`.

The diff ended up a bit noisy because of indentation changes; the key change was adding `Encoding.setLocaleEncoding Encoding.utf8` to the beginning of `main`.

I tested this by reproducing the Unicode error (using `nix-shell --pure`) and checking that the Haskell code change fixes the problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants