cabal
cabal copied to clipboard
Confusing error message when project contains duplicates in 'packages' declaration
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
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.
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.
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 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.
All fail with the same error.
@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.
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.
~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
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?
for those coming in searching by this error message, I got it when I accidentally duplicated the packages: entry in my project file.
Removing any extra copies of *.cabal* from the dir seemed to fix it for me
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.
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.
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.