Skip to content

Require cabal.project packages and/or optional-packages field#11574

Open
tbidne wants to merge 1 commit intohaskell:masterfrom
tbidne:tbidne/7401
Open

Require cabal.project packages and/or optional-packages field#11574
tbidne wants to merge 1 commit intohaskell:masterfrom
tbidne:tbidne/7401

Conversation

@tbidne
Copy link
Contributor

@tbidne tbidne commented Mar 4, 2026

Resolves #7401.

Turns the prior warning into an error. This has the effect that the misleading messages are never logged, since the new error causes an immediate failure.

I attempted to add as many test cases as I could think of, so there may be some redundancy (e.g. I checked explicit vs. implicit targets, and evidently it doesn't matter).

I also added the project file path to the error message. This is grabbed here:

establishProjectBaseContextWithRoot
  :: Verbosity
  -> ProjectConfig
  -> ProjectRoot
  -> CurrentCommand
  -> IO ProjectBaseContext
establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentCommand = do
  let haddockOutputDir = flagToMaybe (packageConfigHaddockOutputDir (projectConfigLocalPackages cliConfig))
  let distDirLayout = defaultDistDirLayout projectRoot mdistDirectory haddockOutputDir

  ...

  -- Get path from distDirLayout here...
  let projPath = distProjectFileMain (distProjectFile distDirLayout)
  when (null (projectPackages projectConfig) && null (projectPackagesOptional projectConfig)) $
    dieWithException verbosity (ProjectConfigNoPackages projPath)

This seems right to me, though someone should double-check this makes sense.

Thanks!


Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@tbidne tbidne force-pushed the tbidne/7401 branch 6 times, most recently from 1918b20 to d6d316c Compare March 10, 2026 21:19
Currently, if a cabal.project file is present and the `packages` and
`optional-packages` fields do not exist, a warning will be issued, and
cabal will fail with a different, potentially misleading error message:

  "There is no <pkgname>.cabal package file or cabal.project file..."

This changes it so that the prior warning is now an error, hence will
cause cabal to fail before the misleading error is given. That at least
one of these fields is required is already specified in the docs, hence
this is not a specification change.

See haskell#7401.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants