haskell / haskell/cabal

confusing error when missing `packages:`

Open
#8,679 11 comments 1 reaction 0 assignees View on GitHub
re: error-message re: project-file type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**
If you forget to include a list of packages in your `cabal.project`, the error looks like this:

```
Warning: There are no packages or optional-packages in the project
Error: cabal: There is no .cabal package file or cabal.project file.
To build packages locally you need at minimum a .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.
```

The warning is spot-on, but the error is confusing, because it can be printed in exactly that way when there is *both* a `.cabal` file and a `cabal.project` file available. For people (like me) that tend to gloss over warnings if there's an error available, that's bad news.

**To Reproduce**
```
$ mkdir t
$ cd t
$ touch cabal.project
$ cabal v2-run t
```

**Expected behavior**
I'm not sure, but probably just rewriting the error is sufficient. Let it reflect more accurately what *actual* check is being done in the code.

**System information**
- cabal-install 3.8.1.0, Cabal 3.8.1.0
- ghc and OS versions are irrelevant I'm pretty sure, but just in case, Linux 5.14 and ghc 8.10.4

**Additional context**
This may be related to #8484, which describes the even-more-confusing error you get when you think "maybe `t` wasn't specific enough" and try `cabal v2-run exe:t` as your first debugging step.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.