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

Better error reporting in raw hls (no wrapper) of invalid project config file (package.yaml, .cabal, stack yaml or cabal.project) #1757

Open
sullyj3 opened this issue Apr 19, 2021 · 2 comments
Labels

Comments

@sullyj3
Copy link

sullyj3 commented Apr 19, 2021

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server version: 1.1.0.0 (GHC: 8.10.4) (PATH: /home/james/.local/bin/haskell-language-server-8.10.4) (GIT hash: f1c096927186a93d8e3ccd4fe8385cc1b070350b)
Tool versions found on the $PATH
cabal:          3.4.0.0
stack:          2.5.1
ghc:            8.10.4

Which OS do you use: Linux (WSL ubuntu)

Which lsp-client do you use: Neovim with CoC

Describe your project (alternative: link to the project): stack new test-hls

Contents of hie.yaml: n/a

Steps to reproduce

  1. Create a new project with stack new test-hls
  2. Make package.yaml invalid in some way, for example, add the line dependencies: under library:, without listing any dependencies.
  3. Open app/Main.hs in your editor. For me, with nvim/CoC, I get
    [coc.nvim] The "languageserver.haskell" server crashed 5 times in the last 3 minutes. The server will not be restarted.

Expected behaviour

Server launches successfully and provides a diagnostic indicating that package.yaml is invalid

Actual behaviour

Server crashes

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

Debug output:
james@SurfaceLaptop ~/d/test-hls> haskell-language-server-8.10.4 --debug
haskell-language-server version: 1.1.0.0 (GHC: 8.10.4) (PATH: /home/james/.local/bin/haskell-language-server-8.10.4) (GIT hash: f1c096927186a93d8e3ccd4fe8385cc1b070350b)
 ghcide setup tester in /home/james/dev/test-hls.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/james/dev/test-hls
Found 4 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
2021-04-19 12:48:19.2446783 [ThreadId 4] DEBUG hls:     Set files of interest to: [(NormalizedFilePath "/home/james/dev/test-hls/app/Main.hs",OnDisk),(NormalizedFilePath "/home/james/dev/test-hls/test/Spec.hs",OnDisk),(NormalizedFilePath "/home/james/dev/test-hls/src/Lib.hs",OnDisk),(NormalizedFilePath "/home/james/dev/test-hls/Setup.hs",OnDisk)]
2021-04-19 12:48:19.2519641 [ThreadId 24] DEBUG hls:    hlint:getIdeas:file:NormalizedFilePath "/home/james/dev/test-hls/src/Lib.hs"
2021-04-19 12:48:19.2519777 [ThreadId 23] DEBUG hls:    hlint:getIdeas:file:NormalizedFilePath "/home/james/dev/test-hls/app/Main.hs"
2021-04-19 12:48:19.252389 [ThreadId 22] DEBUG hls:     hlint:getIdeas:file:NormalizedFilePath "/home/james/dev/test-hls/test/Spec.hs"
2021-04-19 12:48:19.2526386 [ThreadId 24] DEBUG hls:    hlint:getIdeas:file:NormalizedFilePath "/home/james/dev/test-hls/Setup.hs"
2021-04-19 12:48:19.2588852 [ThreadId 30] INFO hls:     Consulting the cradle for "test/Spec.hs"
2021-04-19 12:48:19.2594873 [ThreadId 30] WARNING hls:  No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for test/Spec.hs.
 Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
Output from setting up the cradle Cradle {cradleRootDir = "/home/james/dev/test-hls", cradleOptsProg = CradleAction: Stack}
> /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null
> /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null
2021-04-19 12:48:20.183659 [ThreadId 30] DEBUG hls:     Session loading result: Left [CradleError {cradleErrorDependencies = ["test-hls.cabal","package.yaml","stack.yaml"], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Failed to parse result of calling stack","/home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null"]}]
2021-04-19 12:48:20.1848198 [ThreadId 42] INFO hls:     Consulting the cradle for "app/Main.hs"
2021-04-19 12:48:20.1850276 [ThreadId 42] WARNING hls:  No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for app/Main.hs.
 Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
Output from setting up the cradle Cradle {cradleRootDir = "/home/james/dev/test-hls", cradleOptsProg = CradleAction: Stack}
> /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null
> /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null
2021-04-19 12:48:20.6961111 [ThreadId 42] DEBUG hls:    Session loading result: Left [CradleError {cradleErrorDependencies = ["test-hls.cabal","package.yaml","stack.yaml"], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Failed to parse result of calling stack","/home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null"]}]
2021-04-19 12:48:20.6979682 [ThreadId 54] INFO hls:     Consulting the cradle for "Setup.hs"
2021-04-19 12:48:20.6983063 [ThreadId 54] WARNING hls:  No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for Setup.hs.
 Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2021-04-19 12:48:20.6983419 [ThreadId 29] INFO hls:     File:     /home/james/dev/test-hls/test/Spec.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message:
  Failed to parse result of calling stack
  /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected
  Array, Object, or String, but encountered Null
2021-04-19 12:48:20.7042744 [ThreadId 29] INFO hls:     File:     /home/james/dev/test-hls/app/Main.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message:
  Failed to parse result of calling stack
  /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected
  Array, Object, or String, but encountered Null
Output from setting up the cradle Cradle {cradleRootDir = "/home/james/dev/test-hls", cradleOptsProg = CradleAction: Stack}
2021-04-19 12:48:20.7097394 [ThreadId 54] DEBUG hls:    Session loading result: Left [CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitSuccess, cradleErrorStderr = ["Multi Cradle: No prefixes matched","pwd: /home/james/dev/test-hls","filepath: /home/james/dev/test-hls/Setup.hs","prefixes:","(\"./src\",Stack {component = Just \"test-hls:lib\", stackYaml = Nothing})","(\"./app/Main.hs\",Stack {component = Just \"test-hls:exe:test-hls-exe\", stackYaml = Nothing})","(\"./app/Paths_test_hls.hs\",Stack {component = Just \"test-hls:exe:test-hls-exe\", stackYaml = Nothing})","(\"./test\",Stack {component = Just \"test-hls:test:test-hls-test\", stackYaml = Nothing})"]}]
2021-04-19 12:48:20.7108085 [ThreadId 23] INFO hls:     File:     /home/james/dev/test-hls/Setup.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message:
  Multi Cradle: No prefixes matched
  pwd: /home/james/dev/test-hls
  filepath: /home/james/dev/test-hls/Setup.hs
  prefixes:
  ("./src",Stack {component = Just "test-hls:lib", stackYaml = Nothing})
  ("./app/Main.hs",Stack {component = Just "test-hls:exe:test-hls-exe", stackYaml = Nothing})
  ("./app/Paths_test_hls.hs",Stack {component = Just "test-hls:exe:test-hls-exe", stackYaml =
  Nothing})
  ("./test",Stack {component = Just "test-hls:test:test-hls-test", stackYaml = Nothing})
2021-04-19 12:48:20.711803 [ThreadId 59] INFO hls:      Consulting the cradle for "src/Lib.hs"
2021-04-19 12:48:20.7127651 [ThreadId 59] WARNING hls:  No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Lib.hs.
 Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
Output from setting up the cradle Cradle {cradleRootDir = "/home/james/dev/test-hls", cradleOptsProg = CradleAction: Stack}
> /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null
> /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null
2021-04-19 12:48:21.2348523 [ThreadId 59] DEBUG hls:    Session loading result: Left [CradleError {cradleErrorDependencies = ["test-hls.cabal","package.yaml","stack.yaml"], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Failed to parse result of calling stack","/home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null"]}]
2021-04-19 12:48:21.2354208 [ThreadId 22] INFO hls:     File:     /home/james/dev/test-hls/src/Lib.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message:
  Failed to parse result of calling stack
  /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected
  Array, Object, or String, but encountered Null
Files that failed:
 * /home/james/dev/test-hls/Setup.hs
 * /home/james/dev/test-hls/app/Main.hs
 * /home/james/dev/test-hls/src/Lib.hs
 * /home/james/dev/test-hls/test/Spec.hs

Completed (0 files worked, 4 files failed)
2021-04-19 12:48:21.2368608 [ThreadId 78] INFO hls:     finish: User TypeCheck (took 1.99s)
2021-04-19 12:48:21.2375275 [ThreadId 76] INFO hls:     finish: GetHie (took 0.00s)
2021-04-19 12:48:21.238492 [ThreadId 17] INFO hls:      finish: GenerateCore (took 0.00s)

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs: output of `:CocOpenLog`:
2021-04-19T12:50:30.829 INFO (pid:23136) [services] - registered service "languageserver.haskell"
2021-04-19T12:50:30.840 INFO (pid:23136) [services] - haskell state change: stopped => starting
2021-04-19T12:50:30.843 INFO (pid:23136) [plugin] - coc.nvim 0.0.80-2cece2600a initialized with node: v15.14.0 after 74ms
2021-04-19T12:50:30.988 INFO (pid:23136) [language-client-index] - Language server "languageserver.haskell" started with 23147
2021-04-19T12:50:31.963 INFO (pid:23136) [services] - haskell state change: starting => stopped
2021-04-19T12:50:31.963 INFO (pid:23136) [services] - haskell state change: stopped => starting
2021-04-19T12:50:32.087 INFO (pid:23136) [language-client-index] - Language server "languageserver.haskell" started with 23172
2021-04-19T12:50:32.399 INFO (pid:23136) [services] - haskell state change: starting => stopped
2021-04-19T12:50:32.399 INFO (pid:23136) [services] - haskell state change: stopped => starting
2021-04-19T12:50:32.508 INFO (pid:23136) [language-client-index] - Language server "languageserver.haskell" started with 23197
2021-04-19T12:50:32.830 INFO (pid:23136) [services] - haskell state change: starting => stopped
2021-04-19T12:50:32.830 INFO (pid:23136) [services] - haskell state change: stopped => starting
2021-04-19T12:50:32.956 INFO (pid:23136) [language-client-index] - Language server "languageserver.haskell" started with 23222
2021-04-19T12:50:33.278 INFO (pid:23136) [services] - haskell state change: starting => stopped
2021-04-19T12:50:33.278 INFO (pid:23136) [services] - haskell state change: stopped => starting
2021-04-19T12:50:33.387 INFO (pid:23136) [language-client-index] - Language server "languageserver.haskell" started with 23247
2021-04-19T12:50:33.699 INFO (pid:23136) [services] - haskell state change: starting => stopped
2021-04-19T12:50:54.032 INFO (pid:23136) [attach] - receive notification: openLog []
@Ailrun Ailrun added the type: enhancement New feature or request label Apr 19, 2021
@jneira jneira added type: setup type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Apr 19, 2021
@jneira jneira changed the title Server crash on invalid package.yaml Server crash on invalid project config file (package.yaml, .cabal, stack yaml or cabal.project) Apr 19, 2021
@jneira
Copy link
Member

jneira commented Apr 19, 2021

Thanks for the issue report, i think there was a similar one somewhere about project configuration (not only package.yaml but also stack.yaml, .cabal files or cabal.project) but i cant find it right now.

It already provides some info in the log:

2021-04-19 12:48:21.2354208 [ThreadId 22] INFO hls:     File:     /home/james/dev/test-hls/src/Lib.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message:
  Failed to parse result of calling stack
  /home/james/dev/test-hls/package.yaml: Error while parsing $.library.dependencies - expected
  Array, Object, or String, but encountered Null

and i think the diagnostic will be presented if the server does not crash.

@jneira
Copy link
Member

jneira commented Jan 31, 2022

Nowadays the server does not crash in face of wrong config files and the error is reported in the log:

022-01-31 12:59:57.7287504 [ThreadId 5] INFO hls:	Started LSP server in 0.06s
Couldn't load cradle for libdir: (CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack setup --silent","","D:\\ws\\haskell\\stack-test\\package.yaml: Error while parsing $.library.dependencies - expected Array, Object, or String, but encountered Null\n"]},"d:\\ws\\haskell\\stack-test",Nothing,Cradle {cradleRootDir = "d:\\ws\\haskell\\stack-test", cradleOptsProg = CradleAction: Stack})

But no error in the editor per se, hls "simply" does not provide any feature.
There is a wip to make the wrapper report such errors in the editor: #2591
But it would not improve things if you use the hls server directly
//cc @fendor

@jneira jneira changed the title Server crash on invalid project config file (package.yaml, .cabal, stack yaml or cabal.project) Better error reporting in raw hls (no wrapper) of invalid project config file (package.yaml, .cabal, stack yaml or cabal.project) Jan 31, 2022
@Ailrun Ailrun added component: hie-bios and removed old_type: setup type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants