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

Bad error message: "Failed to find the GHC version of this Cabal project" #1169

Open
noughtmare opened this issue Nov 27, 2024 · 3 comments
Open

Comments

@noughtmare
Copy link

Your environment

Which OS do you use: NixOS

Steps to reproduce

  1. Introduce an error in your .cabal file.
  2. Restart HLS

Expected behaviour

The error should be shown. In my case:

Errors encountered when parsing cabal file ./hirane.cabal:

hirane.cabal:27:7: error:
unexpected 'L'
expecting space, comma, white space or end of input

   26 |       Embedded.Hirane.List
   27 |       Language.Hirane.AST
      |       ^

Actual behaviour

It just shows a generic message:

Failed to find the GHC version of this Cabal project. Error when calling cabal exec -v0 -- ghc --print-libdir

Include debug information

Execute in the root of your project the command haskell-language-server-wrapper --debug . and paste the logs here (you can find the executable location here):

Debug output:
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.9.0.0 x86_64 ghc-9.6.6
Current directory: /home/user/haskell/hirane
Operating system: linux
Arguments: ["--debug","."]
Cradle directory: /home/user/haskell/hirane
Cradle type: Cabal

Tool versions found on the $PATH
cabal:          3.12.1.0
stack:          Not found
ghc:            9.6.6


Consulting the cradle to get project GHC version...
2024-11-27T20:54:34.546282Z | Debug | cabal exec -v0 -- ghc --print-libdir
Failed to find the GHC version of this Cabal project.
Error when calling cabal exec -v0 -- ghc --print-libdir

Errors encountered when parsing cabal file ./hirane.cabal:

hirane.cabal:27:7: error:
unexpected 'L'
expecting space, comma, white space or end of input

   26 |       Embedded.Hirane.List
   27 |       Language.Hirane.AST
      |       ^

Paste the contents of extension specific log, you can check instructions about how to find it here

Extension log:
[Info  - 9:56:18 PM] Stopping the server
2024-11-27T20:56:18.337823Z | Info | LSP: received shutdown
[Info  - 9:56:18 PM] Starting the server
2024-11-27T20:56:18.338501Z | Error | Got EOF
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.9.0.0 x86_64 ghc-9.6.6
Current directory: /home/user/haskell/hirane
Operating system: linux
Arguments: ["--lsp"]
Cradle directory: /home/user/haskell/hirane
Cradle type: Cabal

Tool versions found on the $PATH
cabal:          3.12.1.0
stack:          Not found
ghc:            9.6.6


Consulting the cradle to get project GHC version...
2024-11-27T20:56:18.712954Z | Debug | cabal exec -v0 -- ghc --print-libdir
Failed to find the GHC version of this Cabal project.
Error when calling cabal exec -v0 -- ghc --print-libdir

Errors encountered when parsing cabal file ./hirane.cabal:

hirane.cabal:27:7: error:
unexpected 'L'
expecting space, comma, white space or end of input

   26 |       Embedded.Hirane.List
   27 |       Language.Hirane.AST
      |       ^


 2024-11-27T20:56:18.714257Z | Info | Starting server
2024-11-27T20:56:18.716392Z | Error | LSP: no handler for: "initialized"
2024-11-27T20:56:18.716959Z | Debug | LSP: set new config: {
  "checkProject": true,
  "formattingProvider": "fourmolu",
  "ghcupExecutablePath": "",
  "indentationRules": { "enabled": true },
  "logFile": "",
  "manageHLS": "PATH",
  "maxCompletions": 40,
  "metadataURL": "",
  "openDocumentationInHackage": true,
  "openSourceInHackage": true,
  "plugin": {
    "alternateNumberFormat": { "globalOn": true },
    "cabal": {
      "codeActionsOn": true,
      "completionOn": true,
      "diagnosticsOn": true
    },
    "cabal-fmt": { "config": { "path": "cabal-fmt" } },
    "cabal-gild": { "config": { "path": "cabal-gild" } },
    "callHierarchy": { "globalOn": true },
    "changeTypeSignature": { "globalOn": true },
    "class": { "codeActionsOn": true, "codeLensOn": true },
    "eval": {
      "config": { "diff": true, "exception": false },
      "globalOn": true
    },
    "explicit-fields": { "globalOn": true },
    "explicit-fixity": { "globalOn": true },
    "fourmolu": { "config": { "external": false, "path": "fourmolu" } },
    "gadt": { "globalOn": true },
    "ghcide-code-actions-bindings": { "globalOn": true },
    "ghcide-code-actions-fill-holes": { "globalOn": true },
    "ghcide-code-actions-imports-exports": { "globalOn": true },
    "ghcide-code-actions-type-signatures": { "globalOn": true },
    "ghcide-completions": {
      "config": { "autoExtendOn": true, "snippetsOn": true },
      "globalOn": true
    },
    "ghcide-hover-and-symbols": { "hoverOn": true, "symbolsOn": true },
    "ghcide-type-lenses": { "config": { "mode": "always" }, "globalOn": true },
    "hlint": {
      "codeActionsOn": false,
      "config": { "flags": [  ] },
      "diagnosticsOn": false
    },
    "importLens": { "codeActionsOn": true, "codeLensOn": true },
    "moduleName": { "globalOn": true },
    "ormolu": { "config": { "external": false } },
    "overloaded-record-dot": { "globalOn": true },
    "pragmas-completion": { "globalOn": true },
    "pragmas-disable": { "globalOn": true },
    "pragmas-suggest": { "globalOn": true },
    "qualifyImportedNames": { "globalOn": true },
    "rename": { "config": { "crossModule": false }, "globalOn": true },
    "retrie": { "globalOn": true },
    "semanticTokens": {
      "config": {
        "classMethodToken": "method",
        "classToken": "class",
        "dataConstructorToken": "enumMember",
        "functionToken": "function",
        "moduleToken": "namespace",
        "operatorToken": "operator",
        "patternSynonymToken": "macro",
        "recordFieldToken": "property",
        "typeConstructorToken": "enum",
        "typeFamilyToken": "interface",
        "typeSynonymToken": "type",
        "typeVariableToken": "typeParameter",
        "variableToken": "variable"
      },
      "globalOn": false
    },
    "splice": { "globalOn": true },
    "stan": { "globalOn": false }
  },
  "promptBeforeDownloads": "true",
  "releasesDownloadStoragePath": "",
  "releasesURL": "",
  "serverEnvironment": {  },
  "serverExecutablePath": "",
  "serverExtraArgs": "",
  "sessionLoading": "singleComponent",
  "toolchain": {  },
  "trace": { "client": "info", "server": "off" },
  "upgradeGHCup": true
}
2024-11-27T20:56:18.724522Z | Error | LSP: no handler for: "workspace/didChangeConfiguration"
2024-11-27T20:56:18.725072Z | Debug | VFS: opening file:///home/user/haskell/hirane/src/Language/Hirane/AST.hs
2024-11-27T20:56:18.725567Z | Error | LSP: no handler for: "textDocument/didOpen"
2024-11-27T20:56:18.725808Z | Debug | VFS: opening file:///home/user/haskell/hirane/src/Embedded/Hirane/Nat.hs
2024-11-27T20:56:18.726158Z | Error | LSP: no handler for: "textDocument/didOpen"
2024-11-27T20:56:18.726386Z | Debug | VFS: opening file:///home/user/haskell/hirane/src/MyLib.hs
2024-11-27T20:56:18.726679Z | Error | LSP: no handler for: "textDocument/didOpen"
2024-11-27T20:56:18.727043Z | Debug | LSP: set new config: {
  "checkProject": true,
  "formattingProvider": "fourmolu",
  "ghcupExecutablePath": "",
  "indentationRules": { "enabled": true },
  "logFile": "",
  "manageHLS": "PATH",
  "maxCompletions": 40,
  "metadataURL": "",
  "openDocumentationInHackage": true,
  "openSourceInHackage": true,
  "plugin": {
    "alternateNumberFormat": { "globalOn": true },
    "cabal": {
      "codeActionsOn": true,
      "completionOn": true,
      "diagnosticsOn": true
    },
    "cabal-fmt": { "config": { "path": "cabal-fmt" } },
    "cabal-gild": { "config": { "path": "cabal-gild" } },
    "callHierarchy": { "globalOn": true },
    "changeTypeSignature": { "globalOn": true },
    "class": { "codeActionsOn": true, "codeLensOn": true },
    "eval": {
      "config": { "diff": true, "exception": false },
      "globalOn": true
    },
    "explicit-fields": { "globalOn": true },
    "explicit-fixity": { "globalOn": true },
    "fourmolu": { "config": { "external": false, "path": "fourmolu" } },
    "gadt": { "globalOn": true },
    "ghcide-code-actions-bindings": { "globalOn": true },
    "ghcide-code-actions-fill-holes": { "globalOn": true },
    "ghcide-code-actions-imports-exports": { "globalOn": true },
    "ghcide-code-actions-type-signatures": { "globalOn": true },
    "ghcide-completions": {
      "config": { "autoExtendOn": true, "snippetsOn": true },
      "globalOn": true
    },
    "ghcide-hover-and-symbols": { "hoverOn": true, "symbolsOn": true },
    "ghcide-type-lenses": { "config": { "mode": "always" }, "globalOn": true },
    "hlint": {
      "codeActionsOn": false,
      "config": { "flags": [  ] },
      "diagnosticsOn": false
    },
    "importLens": { "codeActionsOn": true, "codeLensOn": true },
    "moduleName": { "globalOn": true },
    "ormolu": { "config": { "external": false } },
    "overloaded-record-dot": { "globalOn": true },
    "pragmas-completion": { "globalOn": true },
    "pragmas-disable": { "globalOn": true },
    "pragmas-suggest": { "globalOn": true },
    "qualifyImportedNames": { "globalOn": true },
    "rename": { "config": { "crossModule": false }, "globalOn": true },
    "retrie": { "globalOn": true },
    "semanticTokens": {
      "config": {
        "classMethodToken": "method",
        "classToken": "class",
        "dataConstructorToken": "enumMember",
        "functionToken": "function",
        "moduleToken": "namespace",
        "operatorToken": "operator",
        "patternSynonymToken": "macro",
        "recordFieldToken": "property",
        "typeConstructorToken": "enum",
        "typeFamilyToken": "interface",
        "typeSynonymToken": "type",
        "typeVariableToken": "typeParameter",
        "variableToken": "variable"
      },
      "globalOn": false
    },
    "splice": { "globalOn": true },
    "stan": { "globalOn": false }
  },
  "promptBeforeDownloads": "true",
  "releasesDownloadStoragePath": "",
  "releasesURL": "",
  "serverEnvironment": {  },
  "serverExecutablePath": "",
  "serverExtraArgs": "",
  "sessionLoading": "singleComponent",
  "toolchain": {  },
  "trace": { "client": "info", "server": "off" },
  "upgradeGHCup": true
}
2024-11-27T20:56:18.734735Z | Error | LSP: no handler for: "workspace/didChangeConfiguration"
2024-11-27T20:56:18.735322Z | Debug | LSP: set new config: {
  "checkProject": true,
  "formattingProvider": "fourmolu",
  "ghcupExecutablePath": "",
  "indentationRules": { "enabled": true },
  "logFile": "",
  "manageHLS": "PATH",
  "maxCompletions": 40,
  "metadataURL": "",
  "openDocumentationInHackage": true,
  "openSourceInHackage": true,
  "plugin": {
    "alternateNumberFormat": { "globalOn": true },
    "cabal": {
      "codeActionsOn": true,
      "completionOn": true,
      "diagnosticsOn": true
    },
    "cabal-fmt": { "config": { "path": "cabal-fmt" } },
    "cabal-gild": { "config": { "path": "cabal-gild" } },
    "callHierarchy": { "globalOn": true },
    "changeTypeSignature": { "globalOn": true },
    "class": { "codeActionsOn": true, "codeLensOn": true },
    "eval": {
      "config": { "diff": true, "exception": false },
      "globalOn": true
    },
    "explicit-fields": { "globalOn": true },
    "explicit-fixity": { "globalOn": true },
    "fourmolu": { "config": { "external": false, "path": "fourmolu" } },
    "gadt": { "globalOn": true },
    "ghcide-code-actions-bindings": { "globalOn": true },
    "ghcide-code-actions-fill-holes": { "globalOn": true },
    "ghcide-code-actions-imports-exports": { "globalOn": true },
    "ghcide-code-actions-type-signatures": { "globalOn": true },
    "ghcide-completions": {
      "config": { "autoExtendOn": true, "snippetsOn": true },
      "globalOn": true
    },
    "ghcide-hover-and-symbols": { "hoverOn": true, "symbolsOn": true },
    "ghcide-type-lenses": { "config": { "mode": "always" }, "globalOn": true },
    "hlint": {
      "codeActionsOn": false,
      "config": { "flags": [  ] },
      "diagnosticsOn": false
    },
    "importLens": { "codeActionsOn": true, "codeLensOn": true },
    "moduleName": { "globalOn": true },
    "ormolu": { "config": { "external": false } },
    "overloaded-record-dot": { "globalOn": true },
    "pragmas-completion": { "globalOn": true },
    "pragmas-disable": { "globalOn": true },
    "pragmas-suggest": { "globalOn": true },
    "qualifyImportedNames": { "globalOn": true },
    "rename": { "config": { "crossModule": false }, "globalOn": true },
    "retrie": { "globalOn": true },
    "semanticTokens": {
      "config": {
        "classMethodToken": "method",
        "classToken": "class",
        "dataConstructorToken": "enumMember",
        "functionToken": "function",
        "moduleToken": "namespace",
        "operatorToken": "operator",
        "patternSynonymToken": "macro",
        "recordFieldToken": "property",
        "typeConstructorToken": "enum",
        "typeFamilyToken": "interface",
        "typeSynonymToken": "type",
        "typeVariableToken": "typeParameter",
        "variableToken": "variable"
      },
      "globalOn": false
    },
    "splice": { "globalOn": true },
    "stan": { "globalOn": false }
  },
  "promptBeforeDownloads": "true",
  "releasesDownloadStoragePath": "",
  "releasesURL": "",
  "serverEnvironment": {  },
  "serverExecutablePath": "",
  "serverExtraArgs": "",
  "sessionLoading": "singleComponent",
  "toolchain": {  },
  "trace": { "client": "info", "server": "off" },
  "upgradeGHCup": true
}
2024-11-27T20:56:18.745544Z | Debug | LSP: set new config: {
  "checkProject": true,
  "formattingProvider": "fourmolu",
  "ghcupExecutablePath": "",
  "indentationRules": { "enabled": true },
  "logFile": "",
  "manageHLS": "PATH",
  "maxCompletions": 40,
  "metadataURL": "",
  "openDocumentationInHackage": true,
  "openSourceInHackage": true,
  "plugin": {
    "alternateNumberFormat": { "globalOn": true },
    "cabal": {
      "codeActionsOn": true,
      "completionOn": true,
      "diagnosticsOn": true
    },
    "cabal-fmt": { "config": { "path": "cabal-fmt" } },
    "cabal-gild": { "config": { "path": "cabal-gild" } },
    "callHierarchy": { "globalOn": true },
    "changeTypeSignature": { "globalOn": true },
    "class": { "codeActionsOn": true, "codeLensOn": true },
    "eval": {
      "config": { "diff": true, "exception": false },
      "globalOn": true
    },
    "explicit-fields": { "globalOn": true },
    "explicit-fixity": { "globalOn": true },
    "fourmolu": { "config": { "external": false, "path": "fourmolu" } },
    "gadt": { "globalOn": true },
    "ghcide-code-actions-bindings": { "globalOn": true },
    "ghcide-code-actions-fill-holes": { "globalOn": true },
    "ghcide-code-actions-imports-exports": { "globalOn": true },
    "ghcide-code-actions-type-signatures": { "globalOn": true },
    "ghcide-completions": {
      "config": { "autoExtendOn": true, "snippetsOn": true },
      "globalOn": true
    },
    "ghcide-hover-and-symbols": { "hoverOn": true, "symbolsOn": true },
    "ghcide-type-lenses": { "config": { "mode": "always" }, "globalOn": true },
    "hlint": {
      "codeActionsOn": false,
      "config": { "flags": [  ] },
      "diagnosticsOn": false
    },
    "importLens": { "codeActionsOn": true, "codeLensOn": true },
    "moduleName": { "globalOn": true },
    "ormolu": { "config": { "external": false } },
    "overloaded-record-dot": { "globalOn": true },
    "pragmas-completion": { "globalOn": true },
    "pragmas-disable": { "globalOn": true },
    "pragmas-suggest": { "globalOn": true },
    "qualifyImportedNames": { "globalOn": true },
    "rename": { "config": { "crossModule": false }, "globalOn": true },
    "retrie": { "globalOn": true },
    "semanticTokens": {
      "config": {
        "classMethodToken": "method",
        "classToken": "class",
        "dataConstructorToken": "enumMember",
        "functionToken": "function",
        "moduleToken": "namespace",
        "operatorToken": "operator",
        "patternSynonymToken": "macro",
        "recordFieldToken": "property",
        "typeConstructorToken": "enum",
        "typeFamilyToken": "interface",
        "typeSynonymToken": "type",
        "typeVariableToken": "typeParameter",
        "variableToken": "variable"
      },
      "globalOn": false
    },
    "splice": { "globalOn": true },
    "stan": { "globalOn": false }
  },
  "promptBeforeDownloads": "true",
  "releasesDownloadStoragePath": "",
  "releasesURL": "",
  "serverEnvironment": {  },
  "serverExecutablePath": "",
  "serverExtraArgs": "",
  "sessionLoading": "singleComponent",
  "toolchain": {  },
  "trace": { "client": "info", "server": "off" },
  "upgradeGHCup": true
}
2024-11-27T20:56:18.754059Z | Debug | LSP: set new config: {
  "checkProject": true,
  "formattingProvider": "fourmolu",
  "ghcupExecutablePath": "",
  "indentationRules": { "enabled": true },
  "logFile": "",
  "manageHLS": "PATH",
  "maxCompletions": 40,
  "metadataURL": "",
  "openDocumentationInHackage": true,
  "openSourceInHackage": true,
  "plugin": {
    "alternateNumberFormat": { "globalOn": true },
    "cabal": {
      "codeActionsOn": true,
      "completionOn": true,
      "diagnosticsOn": true
    },
    "cabal-fmt": { "config": { "path": "cabal-fmt" } },
    "cabal-gild": { "config": { "path": "cabal-gild" } },
    "callHierarchy": { "globalOn": true },
    "changeTypeSignature": { "globalOn": true },
    "class": { "codeActionsOn": true, "codeLensOn": true },
    "eval": {
      "config": { "diff": true, "exception": false },
      "globalOn": true
    },
    "explicit-fields": { "globalOn": true },
    "explicit-fixity": { "globalOn": true },
    "fourmolu": { "config": { "external": false, "path": "fourmolu" } },
    "gadt": { "globalOn": true },
    "ghcide-code-actions-bindings": { "globalOn": true },
    "ghcide-code-actions-fill-holes": { "globalOn": true },
    "ghcide-code-actions-imports-exports": { "globalOn": true },
    "ghcide-code-actions-type-signatures": { "globalOn": true },
    "ghcide-completions": {
      "config": { "autoExtendOn": true, "snippetsOn": true },
      "globalOn": true
    },
    "ghcide-hover-and-symbols": { "hoverOn": true, "symbolsOn": true },
    "ghcide-type-lenses": { "config": { "mode": "always" }, "globalOn": true },
    "hlint": {
      "codeActionsOn": false,
      "config": { "flags": [  ] },
      "diagnosticsOn": false
    },
    "importLens": { "codeActionsOn": true, "codeLensOn": true },
    "moduleName": { "globalOn": true },
    "ormolu": { "config": { "external": false } },
    "overloaded-record-dot": { "globalOn": true },
    "pragmas-completion": { "globalOn": true },
    "pragmas-disable": { "globalOn": true },
    "pragmas-suggest": { "globalOn": true },
    "qualifyImportedNames": { "globalOn": true },
    "rename": { "config": { "crossModule": false }, "globalOn": true },
    "retrie": { "globalOn": true },
    "semanticTokens": {
      "config": {
        "classMethodToken": "method",
        "classToken": "class",
        "dataConstructorToken": "enumMember",
        "functionToken": "function",
        "moduleToken": "namespace",
        "operatorToken": "operator",
        "patternSynonymToken": "macro",
        "recordFieldToken": "property",
        "typeConstructorToken": "enum",
        "typeFamilyToken": "interface",
        "typeSynonymToken": "type",
        "typeVariableToken": "typeParameter",
        "variableToken": "variable"
      },
      "globalOn": false
    },
    "splice": { "globalOn": true },
    "stan": { "globalOn": false }
  },
  "promptBeforeDownloads": "true",
  "releasesDownloadStoragePath": "",
  "releasesURL": "",
  "serverEnvironment": {  },
  "serverExecutablePath": "",
  "serverExtraArgs": "",
  "sessionLoading": "singleComponent",
  "toolchain": {  },
  "trace": { "client": "info", "server": "off" },
  "upgradeGHCup": true
}
@fendor
Copy link
Collaborator

fendor commented Nov 28, 2024

Thanks for the bug report!

The issue is that this error is shown before HLS is actually launched.
This error is most likely produced by haskell-language-server-wrapper, trying to decide which GHC version to use to compile your project with.
Consequentially, we don't have a VFS, we don't know which file is responsible for loading the cradle, thus, we can't really display a diagnostic. To implement this, we would need to expand the LSP features implemented by the wrapper.
Moreover, the pop-up can only display newline characters, no other kind of formatting is supported.
If we displayed the full error message, it would be completely unreadable.

In the future, the situation might be improved via the cabal path command, as this doesn't resolve the .cabal file, allowing the wrapper to launch the HLS binary and getting proper diagnostics.

To use cabal path, we need to update hie-bios.

@noughtmare
Copy link
Author

Moreover, the pop-up can only display newline characters, no other kind of formatting is supported.
If we displayed the full error message, it would be completely unreadable.

As a very low tech solution, could the pop-up show a button that when clicked opens a new temporary file which contains the full error text?

Another idea I have is that it could point out that the user can run cabal build manually to see the full error.

@fendor
Copy link
Collaborator

fendor commented Nov 28, 2024

As a very low tech solution, could the pop-up show a button that when clicked opens a new temporary file which contains the full error text?

Yeah, we could do that. We would need to extract the message from hie-bios, and then implement the pop-up.

Adapting the message is also possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants