cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Confusing error message when project contains duplicates in 'packages' declaration

Open dmwit opened this issue 6 years ago • 14 comments

Describe the bug I see the following behavior:

% cabal v2-repl
Resolving dependencies...
TODO: add support for multiple packages in a directory
CallStack (from HasCallStack):
  error, called at ./Distribution/Client/ProjectOrchestration.hs:532:9 in main:Distribution.Client.ProjectOrchestration
CallStack (from -prof):
  Distribution.Client.ProjectOrchestration.resolveTargets (Distribution/Client/ProjectOrchestration.hs:(502,1)-(608,34))
  Distribution.Client.ProjectOrchestration.CAF (<entire-module>)
  1.10s user 0.16s system 98% cpu 1.282 total
zsh: exit 1

To Reproduce Set up a directory that matches mine:

% tree
.
├── a
│   └── a.cabal
└── b
    ├── b.cabal
    └── cabal.project.local

2 directories, 3 files
% cat a/a.cabal
name:                a
version:             0.1.0.0
build-type:          Simple
% cat b/b.cabal
name:                b
version:             0.1.0.0
build-type:          Simple
% cat b/cabal.project.local
packages: ./
          ../a/

Navigate to the b directory, then run cabal v2-repl.

System information

% cabal --version
cabal-install version 2.4.1.0
compiled using version 2.4.1.0 of the Cabal library 

dmwit avatar Aug 17 '19 19:08 dmwit

I can reproduce this with master, but it doesn't seem to happen when the packages: declaration is in cabal.project file (as would be normal) instead of cabal.project.local. Strange.

DanielG avatar Aug 19 '19 15:08 DanielG

First good step to debugging would be to expand that error message to contain more info: which two packages are duplicated?

I won’t be surprised if it’s b.cabal which is duplicated, as it’s implied by default packages in cabal.project

On 19 Aug 2019, at 18.52, Daniel Gröber (dxld) [email protected] wrote:

I can reproduce this, but it doesn't seem to happen when the packages: declaration is in cabal.project file (as would be normal) instead of cabal.project.local. Strange.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

phadej avatar Aug 19 '19 18:08 phadej

Ah, you're totally right!

TODO: add support for multiple packages in a directory
TargetPackage TargetImplicitCwd [PackageIdentifier {pkgName = PackageName "repro-b", pkgVersion = mkVersion [0,1,0,0]},PackageIdentifier {pkgName = PackageName "repro-b", pkgVersion = mkVersion [0,1,0,0]}] Nothing
CallStack (from HasCallStack):
  error, called at ./Distribution/Client/ProjectOrchestration.hs:542:9 in main:Distribution.Client.ProjectOrchestration

I guess this is just confusing behaviour and not a bug then.

DanielG avatar Aug 19 '19 18:08 DanielG

@DanielG as you are on it, what happens if one have cabal.projects like:

-- identical
packages: b.cabal
packages: b.cabal

or

-- not obviously the same
packages: b.cabal
packages: .
packages: b.cabal
packages: *.cabal

If all three fail, then we have "bad error message" problem. Otherwise, we have inconsistent behavior which is a bug.

phadej avatar Aug 19 '19 18:08 phadej

All fail with the same error.

DanielG avatar Aug 19 '19 18:08 DanielG

@DanielG good. Then the task is clear: someone have to improve the error message. (I'm not implying you have to do it).

I'd say, we shouldn't imply that multiple .cabal in the same folder would work any time soon. At least until someone is started to work on that feature for real.

phadej avatar Aug 19 '19 18:08 phadej

I had a look at the code and I might have a crack at the cabal file thing when I have some motivation actually. Seems to me like there's just some hooking-up required. We should still detect real duplicates though since those don't really make sense even if you can have multiple packages in one directory.

DanielG avatar Aug 19 '19 18:08 DanielG

~I'm not sure I understand above, but why should new-repl fail with this error while new-build succeeds? I'm now using cabal install 3.2, on ghc 8.10.1.~ EDIT: nevermind

jberryman avatar Apr 15 '20 15:04 jberryman

I think the least surprising thing, if there are two identical package blocks, is to append the second to the first (possibly overriding some settings from the previous one). This is morally how cabal.project and cabal.project.local relate to each other, no?

jberryman avatar Apr 20 '20 17:04 jberryman

for those coming in searching by this error message, I got it when I accidentally duplicated the packages: entry in my project file.

KiaraGrouwstra avatar Apr 27 '20 11:04 KiaraGrouwstra

Removing any extra copies of *.cabal* from the dir seemed to fix it for me

kaustavha avatar Jul 23 '20 02:07 kaustavha

I came across this problem when I put the packages: directive in cabal.project.local rather than cabal.project, by mistake. I submitted https://github.com/haskell/cabal/pull/7078 in the hope this provides the user with slightly more useful information.

tomjaguarpaw avatar Sep 17 '20 17:09 tomjaguarpaw

I still experience this problem with 3.8.1.0. The problem is that the same package can be listed several times across present and implied project files. Perhaps the easiest way out is to nub the list of packages (including their locations in the file system and names) so that only one copy of every package remains on the list? That is to say, we should only keep one copy of every address, where an address of a package is a tuple of its location in the file system and name.

kindaro avatar Oct 03 '22 13:10 kindaro

That's probably the best choice. The only drawback is that when a user instead of "a, b, c" writes "a, b, a", no error would be printed at this point. Not sure how common such kinds of typos are. We could warn, perhaps.

Mikolaj avatar Oct 24 '22 16:10 Mikolaj