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

cabal-install generates a confusing error message #9045

Open
ddrone opened this issue Jun 19, 2023 · 7 comments
Open

cabal-install generates a confusing error message #9045

ddrone opened this issue Jun 19, 2023 · 7 comments
Labels
blocked: ghc blocked: upstream re: error-message Concerning error messages delivered to the user

Comments

@ddrone
Copy link

ddrone commented Jun 19, 2023

Describe the bug
If a source tries to import modules that are available from another version of package the project already depends on the error message cabal-install generates is extremely confusing:

app/Main.hs:4:1: error:
    Could not load module ‘Language.LSP.Types’
    It is a member of the hidden package ‘lsp-types-1.6.0.0’.
    Perhaps you need to add ‘lsp-types’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘lsp-types-1.6.0.0’.
    Perhaps you need to add ‘lsp-types’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import Language.LSP.Types
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
Error: cabal: Failed to build exe:bad-cabal from bad-cabal-0.1.0.0.

To Reproduce
Steps to reproduce the behavior:

$ git clone https://github.com/ddrone/cabal-issue-repro
$ cd cabal-issue-repro
$ cabal v2-build

Expected behavior
I would prefer in this scenario to not have any package suggestions at all, but the other option would be to check during the error message generation to see whether the dependency is already there, and if it is, to display which version of the package it actually resolves to.

System information

$ cabal --version
cabal-install version 3.10.1.0
compiled using version 3.10.1.0 of the Cabal library
@geekosaur
Copy link
Collaborator

This message is from ghc, not cabal, despite its mentioning cabal. And it is probably hard to change.

@geekosaur
Copy link
Collaborator

(wearing ghc hat, not cabal hat, since this is a more general problem)

I'm going to assume that comment is because of ghc suggesting a cabal-specific alternative. It used to suggest -package, which was strictly worse if you do use stack or cabal: if it worked at all it would completely break their solvers.

Alternatives require either much tighter integration between stack/cabal and ghc, or that they do more work to hide alternative package versions (which would probably make the error message worse in other ways). And I'm not sure what else you can do to convey "if you want to use this module, you need to use this version of your dependency".

@fendor
Copy link
Collaborator

fendor commented Jun 20, 2023

The error message could be improved, still! Since GHC knows you depend on some other version of that exact dependency, it could present you with that information. In the error message, it looks like you are not depending on lsp-types at all.

So, in addition to the seen message, I think it would make sense in GHC to at least mention "hey, you are actually depending on this already, maybe the module name has changed". Or it can at least mention, that this module is not exported from lsp-types-2.0.1. Is that not an improvement here?

@ulysses4ever ulysses4ever added the re: error-message Concerning error messages delivered to the user label Jun 20, 2023
@ulysses4ever
Copy link
Collaborator

Steps to reproduce the behavior:

Doesn't reproduce for me. What I see is:

app/Main.hs:4:1: error:
    Could not find module ‘Language.LSP.Types’
    Perhaps you meant
      Language.LSP.VFS (from lsp-2.0.0.0)
      Language.LSP.Server (from lsp-2.0.0.0)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import Language.LSP.Types
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
Error: cabal: Failed to build exe:bad-cabal from bad-cabal-0.1.0.0.

Which is a perfectly sensible error message imo. It seems that something funny is going on with your environment. Have you used cabal install --lib by any chance? E.g. this does reproduce the message you show:

❯ cabal install --ignore-project --lib --package-env=. lsp-types-1.6.0.0
...

❯ cabal build                                                                                         0 (03:09.026) < 19:51:04
Build profile: -w ghc-9.6.1 -O1
In order, the following will be built (use -v for more details):
 - bad-cabal-0.1.0.0 (exe:bad-cabal) (first run)
Preprocessing executable 'bad-cabal' for bad-cabal-0.1.0.0..
Building executable 'bad-cabal' for bad-cabal-0.1.0.0..
[1 of 1] Compiling Main             ( app/Main.hs, /data/artem/cabal/t9045-confusing-error-message/cabal-issue-repro/dist-newstyle/build/x86_64-linux/ghc-9.6.1/bad-cabal-0.1.0.0/x/bad-cabal/build/bad-cabal/bad-cabal-tmp/Main.o )

app/Main.hs:4:1: error:
    Could not load module ‘Language.LSP.Types’
    It is a member of the hidden package ‘lsp-types-1.6.0.0’.
    Perhaps you need to add ‘lsp-types’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import Language.LSP.Types
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
Error: cabal: Failed to build exe:bad-cabal from bad-cabal-0.1.0.0.

In that case, I think, it's a perfectly sensible error message: basically, you asked cabal to make lsp-types-1.6.0.0 available to GHC, but the build doesn't pick this (version of) the package (rightly so: the version is disallowed by existing constraints), so GHC sees it but can't use it.

All in all, we're keep getting into trouble because cabal install --lib is ill-designed...


@fendor

it can at least mention, that this module is not exported from lsp-types-2.0.1.

How would "it" (GHC, Cabal, whatever) know which package to blame? This module "is not exported" from thousand other packages that you can depend upon. Do you think "it" should be clever enough to match lsp-types-1.6.0.0, which is hidden but does contain the module, and lsp-types-2.0.1, which is in use but doesn't contain the module. Perhaps this would be nice. Maybe someone should raise a GHC ticket. But really, the way cabal-install and GHC are supposed to work, this situation shouldn't come up often: cabal shouldn't provide GHC with two versions of the same package... I blame cabal install --lib here again.

@ddrone
Copy link
Author

ddrone commented Jun 21, 2023

It seems that something funny is going on with your environment.

I can provide more information about the environment if that would help, but I have no idea what information would be useful. I don't remember whether I ran cabal install --lib on anything.

In that case, I think, it's a perfectly sensible error message

I disagree. In particular, the conjunction of

  1. lsp-types being present in .cabal file
  2. GHC suggesting Perhaps you need to add ‘lsp-types’ to the build-depends in your .cabal file.

looks like a contradiction to me, and was extremely confusing. I'd say a better error message would be something like

    It is a member of the hidden package ‘lsp-types-1.6.0.0’.
    Perhaps you need to add ‘lsp-types = 1.6.0.0’ to the build-depends in your .cabal file.
    Version of 'lsp-types' you have in your package environment is '2.0.0.0'

@rosshjb
Copy link

rosshjb commented Aug 25, 2023

After doing cabal install --lib, the base is still unavailable too.

@gbaz
Copy link
Collaborator

gbaz commented Aug 25, 2023

After doing cabal install --lib, the base is still unavailable too.

Fixed in next release: #8903

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: ghc blocked: upstream re: error-message Concerning error messages delivered to the user
Projects
None yet
Development

No branches or pull requests

7 participants