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

Weeder fails with hPutChar error if dhall spits out unexpected unicode #86

Open
brprice opened this issue Sep 22, 2021 · 2 comments
Open

Comments

@brprice
Copy link

brprice commented Sep 22, 2021

dhall explicitly ignores locale settings for output (dhall-lang/dhall-haskell#188) which can cause problems if weeder is running in a non-utf8 environment. I don't know if it is worth compensating for this in weeder, but I hope that this bug report can at least save others time spend debugging this!

E.g.

$ LC_ALL=C XDG_CACHE_HOME=/nonexistent weeder

Warning: Could not get or create the default cache directory:

weeder: <stderr>: hPutChar: invalid argument (invalid character)

More realistically, this happens when naively running weeder in CI via nix (for the same reason).

Note that dhall's error message (which contains unicode and seems to be echoed by weeder) starts

Warning: Could not get or create the default cache directory:

↳ /nonexistent/dhall-haskell

As a workaround to this issue, one can either:

  • ensure dhall does not spit out errors (e.g. set XDG_CACHE_HOME to something sensible, I do not know if there are other common errors to avoid)
  • or ensure weeder runs in a UTF8 locale.
@brprice
Copy link
Author

brprice commented Sep 22, 2021

Also, be aware of dhall-lang/dhall-haskell#797: dhall has --ascii and --plain flags, but they currently do not affect error messages.

@brprice
Copy link
Author

brprice commented Sep 22, 2021

A minimal example of the problem is

{-# LANGUAGE OverloadedStrings #-}
import Dhall

main :: IO ()
main = Dhall.input Dhall.unit "./weeder.dhall"

running via ghc encoding-problem.hs && LC_ALL=C XDG_CACHE_HOME=/nonexistent ./encoding-problem.

Dhall will explicitly print a utf-8 string to stderr if Dhall.Import.getOrCreateCacheDirectory fails. Weeder opens handles in the system locale and chokes on the non-ascii characters. This does not happen when running dhall directly since it always opens handles in utf8 mode.

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

1 participant