cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Misleading error message when `cabal.project` does not have `packages` field

Open augustss opened this issue 3 years ago • 14 comments

The error message claims there is no .cabal file nor a cabal.project, when in fact they both exist.

Verse$ cabal --version
cabal-install version 3.4.0.0
compiled using version 3.4.0.0 of the Cabal library
Verse$ cabal build
Warning: There are no packages or optional-packages in the project
cabal.exe: There is no <pkgname>.cabal package file or cabal.project file. To
build packages locally you need at minimum a <pkgname>.cabal file. You can use
'cabal init' to create one.

For non-trivial projects you will also want a cabal.project file in the root
directory of your project. This file lists the packages in your project and
all other build configuration. See the Cabal user guide for full details.

Verse$ ls -l
total 14
-rw-r--r-- 1 lennart.augustsson Domain Users   14 May 18 17:18 cabal.project
-rw-r--r-- 1 lennart.augustsson Domain Users  113 May 18 16:33 CHANGELOG.md
drwxr-xr-x 1 lennart.augustsson Domain Users    0 May 18 15:39 dist-newstyle
drwxr-xr-x 1 lennart.augustsson Domain Users    0 May 18 17:12 src
-rw-r--r-- 1 lennart.augustsson Domain Users 1305 May 18 17:15 Verse.cabal

augustss avatar May 19 '21 00:05 augustss

mmm, i guess cabal.project has no packages field or it does not point to any dir containing a .cabal file. The message is wrong in this case but

For non-trivial projects you will also want a cabal.project file in the root
directory of your project. This file lists the packages in your project and
all other build configuration.

gives some clue, maybe not so helpful as it should be though

jneira avatar May 19 '21 05:05 jneira

The clearly wrong part is:

cabal.exe: There is no <pkgname>.cabal package file or cabal.project file. To
build packages locally you need at minimum a <pkgname>.cabal file. You can use
'cabal init' to create one.

there is a cabal.project and a <pkgname>.cabal file in the current dir

jneira avatar Jun 15 '21 07:06 jneira

I would labeled this as a bug, as there is a clearly wrong error message.

Warning: There are no packages or optional-packages in the project should be an error, an the unique one, at least in this case

jneira avatar Jun 15 '21 08:06 jneira

In #5121 it was suggested to replace

cabal: There is no <pkgname>.cabal package file or cabal.project file. 
To build packages locally you need at minimum a <pkgname>.cabal file. 
You can use 'cabal init' to create one.

text into something like

There is no <pkgname>.cabal package file or the currently active cabal.project configuration (if one exists) doesn't specify any packages. 
To build packages locally you need at minimum a <pkgname>.cabal file. 
You can use 'cabal init' to create one.

but i am not convinced is good enough

jneira avatar Jun 19 '22 19:06 jneira

You mean in https://github.com/haskell/cabal/issues/5121? I think the first line of the new message is fine. I'd add one extra sentence:

If you additionally create a cabal.project or cabal.project.local file, one of them must have a "packages: ..." section.

(or "stanza" or however we consistently name such things). This also prevents adding packages: to both files and wondering at errors from having them concatenated.

Mikolaj avatar Jun 20 '22 09:06 Mikolaj

You mean in https://github.com/haskell/cabal/issues/5121? I think the first line of the new message is fine.

Yeah it was 5121 (i ve corrected the comment) The problem is the message is growing and growing, trying to catch all the cases and it will get outdated quickly. I think the root problem is the code building the message should have enough info to discern cases and be more precise and more helpful (the info could be used to point to the concrete error and create a more useful suggestion). And that root problem is behind of most poor error messages imho.

But dont let the perfect be the enemy of the good, it could be a improvement.

jneira avatar Jun 20 '22 19:06 jneira

Agreed. More precise message would be even better.

Mikolaj avatar Jun 20 '22 19:06 Mikolaj

Related; #5850. There is a pr to improve docs, but the error message should help too and it is more important than docs.

jneira avatar Jul 18 '22 21:07 jneira

And the error should be clear and concide: The project file <cabal.project or custom one> misses the required field 'packages'

jneira avatar Jul 18 '22 21:07 jneira

Fixed in #8300. Closing.

Mikolaj avatar Jul 20 '22 15:07 Mikolaj

Actually, this one is not about the docs but about the error message. I can swear I saw a ticket like that but about the docs...

ulysses4ever avatar Jul 20 '22 15:07 ulysses4ever

Apologies, it's not fixed. It's now, sort of, explained in the docs, but the commandline message should be improved as well.

Mikolaj avatar Jul 20 '22 15:07 Mikolaj

@ulysses4ever: right, I got used to do what you say without thinking, but this one time you got it wrong. :D

Mikolaj avatar Jul 20 '22 15:07 Mikolaj

This also happens btw if you have a cabal.project in a parent directory that you forgot about. I found out by running cabal with -v3 and noticing the cabal.project in the parent directory in the output.

Maybe our error should mention that there is a cabal.project at play and where it is.

lf- avatar Feb 27 '24 23:02 lf-