Skip to content

Fails to load when cabal file contains non-ASCII characters #1926

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

Closed
chris-martin opened this issue Jun 15, 2021 · 9 comments
Closed

Fails to load when cabal file contains non-ASCII characters #1926

chris-martin opened this issue Jun 15, 2021 · 9 comments
Labels
can-workaround component: implicit-hie os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@chris-martin
Copy link

I have an example here of a project that crashes haskell-language-server because the cabal file contains an em dash. If I remove the offending character, then HLS works.

Couldn't figure out what GHC version the project is using: /home/chris/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-wrapper-1.2.0-linux --project-ghc-version exited with exit code 1: No 'hie.yaml' found. Try to discover the project type! haskell-language-server-wrapper-1.2.0-linux: /home/chris/environment-variables/environment-variables.cabal: hGetContents: invalid argument (invalid byte sequence)

Screenshot from 2021-06-15 03-04-40

  • OS: NixOS 21.05
  • lsp-client: VSCode
  • no hie.yaml file
@jneira jneira added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. type: setup labels Jun 15, 2021
@jneira
Copy link
Member

jneira commented Jun 15, 2021

Thanks you for reporting the issue. Until the bug is fixed a possible workaround could be generate an explicit hie.yaml file using the utility gen-hie (you can get it with cabal install implicit-hie)
Maybe you will have to remove the unicode char to make it work, but once the file is generated you can add it again.

@chris-martin
Copy link
Author

Thanks for the workaround, that does work.

@jneira
Copy link
Member

jneira commented Jun 17, 2021

Hmm, i cant reproduce with hls 1.1 in windows adding this line to my cabal file: description: With unicode char → —
Will try with 1.2

EDIT: hls-1.2.0 works for me too

D:\ws\haskell\cabal-test>haskell-language-server-wrapper
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper)
 Version 1.2.0.0, Git revision be2071e985cb417f984ab00a1aad76dee02d6d0b (dirty)
x86_64 ghc-8.10.4
Current directory: D:\ws\haskell\cabal-test
Operating system: mingw32
Arguments: []
Cradle directory: D:\ws\haskell\cabal-test
Cradle type: Cabal

Tool versions found on the $PATH
cabal:          3.4.0.0
stack:          2.6.0
ghc:            8.8.4


Consulting the cradle to get project GHC version...
Project GHC version: 8.8.4
haskell-language-server exe candidates: ["haskell-language-server-8.8.4.exe","haskell-language-server.exe"]
Launching haskell-language-server exe at:D:\bin\hls\haskell-language-server-8.8.4.exe
haskell-language-server version: 1.2.0.0 (GHC: 8.8.4) (PATH: D:\bin\hls\haskell-language-server-8.8.4.exe)
 ghcide setup tester in D:\ws\haskell\cabal-test.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in D:\ws\haskell\cabal-test
Found 6 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
  ()

Step 3/4: Initializing the IDE

Step 4/4: Type checking the files
............
Files that failed:
 * D:\ws\haskell\cabal-test\src\MyPrefix\MyModuleExe.hs

Completed (5 files worked, 1 file failed)
2021-06-17 11:05:51.066693 [ThreadId 178] INFO hls:     finish: GenerateCore (took 0.00s)
haskell-language-server-wrapper: callProcess: D:\bin\hls\haskell-language-server-8.8.4.exe (exit 1): failed

@ncfavier
Copy link

ncfavier commented Sep 4, 2021

Can confirm having the same issue with the VSCode extension on NixOS.

@ncfavier
Copy link

ncfavier commented Sep 4, 2021

Solved by installing nixpkgs' haskell-language-server instead of using the one managed by the extension.

@jneira
Copy link
Member

jneira commented Jan 31, 2022

It seems this is not reproduced with newer hls versions, feel free to reopen ion other case

@jneira jneira closed this as completed Jan 31, 2022
@gusbicalho
Copy link

FYI, I just ran into this bug with hls 1.7.0. The log below shows the cabal file as text and hex dump.

It turned out that the problem was that the VM I was using had locales set to POSIX. Once I fixed things so that it got a UTF-8 locale, HLS worked again. I imagine this means hGetContents uses the system locale to pick an encoding, and if the locale is not UTF-8 it breaks down on multi-byte chars (?)

$ ls -la
total 28
drwxr-xr-x  2 gusbicalho gusbicalho  4096 Apr 29 19:16 .
drwxrwxrwt 69 root       root       20480 Apr 29 19:15 ..
-rw-r--r--  1 gusbicalho gusbicalho   157 Apr 29 19:15 repro-utf8.cabal

$ cat repro-utf8.cabal
cabal-version: 2.0
name: repro-utf8
build-type: Simple
version: 0.1.0.0
author: lön

library
    default-language: Haskell98
    build-depends: base == 4.*

$ od -t cx1 repro-utf8.cabal
0000000   c   a   b   a   l   -   v   e   r   s   i   o   n   :       2
         63  61  62  61  6c  2d  76  65  72  73  69  6f  6e  3a  20  32
0000020   .   0  \n   n   a   m   e   :       r   e   p   r   o   -   u
         2e  30  0a  6e  61  6d  65  3a  20  72  65  70  72  6f  2d  75
0000040   t   f   8  \n   b   u   i   l   d   -   t   y   p   e   :
         74  66  38  0a  62  75  69  6c  64  2d  74  79  70  65  3a  20
0000060   S   i   m   p   l   e  \n   v   e   r   s   i   o   n   :
         53  69  6d  70  6c  65  0a  76  65  72  73  69  6f  6e  3a  20
0000100   0   .   1   .   0   .   0  \n   a   u   t   h   o   r   :
         30  2e  31  2e  30  2e  30  0a  61  75  74  68  6f  72  3a  20
0000120   l 303 266   n  \n  \n   l   i   b   r   a   r   y  \n
         6c  c3  b6  6e  0a  0a  6c  69  62  72  61  72  79  0a  20  20
0000140           d   e   f   a   u   l   t   -   l   a   n   g   u   a
         20  20  64  65  66  61  75  6c  74  2d  6c  61  6e  67  75  61
0000160   g   e   :       H   a   s   k   e   l   l   9   8  \n
         67  65  3a  20  48  61  73  6b  65  6c  6c  39  38  0a  20  20
0000200           b   u   i   l   d   -   d   e   p   e   n   d   s   :
         20  20  62  75  69  6c  64  2d  64  65  70  65  6e  64  73  3a
0000220       b   a   s   e       =   =       4   .   *  \n
         20  62  61  73  65  20  3d  3d  20  34  2e  2a  0a
0000235

$ cabal build
Resolving dependencies...
Build profile: -w ghc-9.2.2 -O1
In order, the following will be built (use -v for more details):
 - repro-utf8-0.1.0.0 (lib) (first run)
Configuring library for repro-utf8-0.1.0.0..
Preprocessing library for repro-utf8-0.1.0.0..
Building library for repro-utf8-0.1.0.0..

$ haskell-language-server-wrapper-1.7.0.0
No 'hie.yaml' found. Try to discover the project type!
haskell-language-server-wrapper-1.7.0.0: /tmp/repro-utf8/repro-utf8.cabal: hGetContents: invalid argument (invalid byte sequence)

@isomorpheme
Copy link

I also seem to be having the same issue, having built 1.7.0.0. from source.

@istathar
Copy link

istathar commented Dec 1, 2022

I'm hitting this. haskell-language-server 1.8.0.0's haskell-language-server works fine from command line but when run from within VSCode it results in

thing.cabal: hGetContents: invalid argument (invalid byte sequence)

It's possible that the problem traces to the builtin gen-hie code supplied by implict-hie (and possibly further to Cabal-syntax). It is POSSIBLE that an explicit hie.yaml file containing, in my case nothing more than

cradle:
  stack:

might act as a workaround suppressing the implicit hie code path. It's working? but if so, fragile. Unclear whether something Nix is doing might be triggering the localization issue; code developed on the underlying Fedora system works (or was working) fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can-workaround component: implicit-hie os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

7 participants