Skip to content

cabal install prints unhelpful error when .cabal filename does not match the package name #7322

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

Open
falsifian opened this issue Mar 9, 2021 · 4 comments · May be fixed by #10947
Open

cabal install prints unhelpful error when .cabal filename does not match the package name #7322

falsifian opened this issue Mar 9, 2021 · 4 comments · May be fixed by #10947

Comments

@falsifian
Copy link

Describe the bug

In a project where the .cabal file has underscores in the name, cabal install fails with an unhelpful error message:

dieVerbatim: user error (cabal: Package .cabal file not found in the tarball:
/tmp/cabal-install.-42328/dist-newstyle/tmp/src-42328/note-graph-0.0.0.0/note-graph.cabal
)

After much head-scratching, I realized the problem was I needed to rename note_graph.cabal to note-graph.cabal.

To Reproduce
Steps to reproduce the behavior:

  • Put the following in a file called a_b.cabal.
cabal-version: 2.2
name: a-b
version: 0.0.0.0
build-type: Simple

executable x
  default-language: Haskell2010
  build-depends: base
  main-is: Main.hs
  • Put something in Main.hs.
  • cabal v2-install .:x

Expected behavior

One of the following would be preferrable:

  • The installation works.
  • Cabal prints an error like Your .cabal file should not have underscores in the name.

System information
OpenBSD current

I've got custom-built ghc and cabal-install ports; let me know if you'd like me to retry with an unmodified install.

The Glorious Glasgow Haskell Compilation System, version 8.6.4
falsifian moth d $ cabal --version
cabal-install version 3.4.0.0
compiled using version 3.4.0.0 of the Cabal library```


@jneira
Copy link
Member

jneira commented Jun 13, 2021

@falsifian thanks for reporting the error which i can reproduce with last cabal-3.4.0.0
Points to consider:

  • cabal v2-build lets you build packages which .cabal file name differs from the package name described in that file (it is any difference ,not only between - and _)
  • but cabal install generates a package.tar distribution file and then uses it to install the package like it would downloaded it from hackage. This install from a tar file needs that the .cabal file name matches exactly the package name, so it fails
  • that means the package will not be able to be uploaded to hackage as cabal check tell us:
PS D:\dev\ws\haskell\cabal-test> cabal check
Warning: The filename .\cabal_test.cabal does not match package name
(expected: cabal-test.cabal)
Warning: Hackage would reject this package.

So we could do:

  • Convert the warning in cabal check in an error for cabal install and cabal build
  • Fix cabal install to match the behaviour of cabal build and not throw an error only for local tars generated by cabal install itself, i guess it will be tricky
  • Throw an error in cabal install using the same code cabal check uses to print the warning

Imo the build and install behaviour should be coherent and throw an error, but if it is already a warning is cause someone would be using .cabal names different from package names locally (???).
So i would vote for 2, although 3 will be easier to implement i guess

@jneira jneira changed the title cabal install prints unhelpful error when .cabal filename has underscores cabal install prints unhelpful error when .cabal filename does not match the package name Jun 13, 2021
@falsifian
Copy link
Author

@jneira Thanks for the analysis. I don't have strong opinions or intimate knowledge of cabal, so I'll leave the discussion to others here and in #6299. I've learned the lesson already, so it's not a problem for me unless I forget :)

@andreasabel andreasabel added the re: error-message Concerning error messages delivered to the user label Aug 29, 2021
@jneira
Copy link
Member

jneira commented Nov 8, 2021

As a easier to do improvement, we could improve the actual error message, without touching actual semantics

@mmhat mmhat linked a pull request May 6, 2025 that will close this issue
6 tasks
@mmhat
Copy link

mmhat commented May 6, 2025

While my intention was primarily to improve the workflow with name-agnostic Cabal files (e.g. package.cabal regardless of the actual package name), I accidentally implemented a fix for this in #10947:
There, the Cabal file is renamed to PACKAGE_NAME.cabal in the source distribution archive.

Would this be an acceptable solution at all? If so, then there a some open questions regarding the approach:

  1. The main concern, as pointed out by @ulysses4ever , is whether this breaks existing workflows or not. What are the options to mitigate that?
  2. Should the changed behaviour hidden behind a feature flag? Alternatively: Should there be an option to restore the old behaviour?
  3. Should there be a warning when the renaming happens?

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

Successfully merging a pull request may close this issue.

5 participants