Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dmwit opened this issue Aug 17, 2019 · 14 comments

Comments

@dmwit
Copy link
Collaborator

dmwit commented Aug 17, 2019

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 
@DanielG
Copy link
Collaborator

DanielG commented Aug 19, 2019

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.

@phadej
Copy link
Collaborator

phadej commented Aug 19, 2019 via email

@DanielG
Copy link
Collaborator

DanielG commented Aug 19, 2019

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.

@phadej
Copy link
Collaborator

phadej commented Aug 19, 2019

@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.

@DanielG
Copy link
Collaborator

DanielG commented Aug 19, 2019

All fail with the same error.

@phadej
Copy link
Collaborator

phadej commented Aug 19, 2019

@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.

@DanielG DanielG changed the title v2-repl fails if the project includes two directories (?) Confusing error message when project contains duplicates in 'packages' declaration Aug 19, 2019
@DanielG
Copy link
Collaborator

DanielG commented Aug 19, 2019

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.

@jberryman
Copy link

jberryman commented Apr 15, 2020

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
Copy link

jberryman commented Apr 20, 2020

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?

@KiaraGrouwstra
Copy link

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

@kaustavha
Copy link

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

@tomjaguarpaw
Copy link
Member

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

tomjaguarpaw added a commit to tomjaguarpaw/cabal that referenced this issue Sep 17, 2020
tomjaguarpaw added a commit to tomjaguarpaw/cabal that referenced this issue Sep 17, 2020
tomjaguarpaw added a commit to tomjaguarpaw/cabal that referenced this issue Sep 17, 2020
tomjaguarpaw added a commit to tomjaguarpaw/cabal that referenced this issue Sep 17, 2020
phadej pushed a commit to phadej/cabal that referenced this issue Sep 24, 2020
hololeap pushed a commit to hololeap/cabal that referenced this issue Apr 24, 2022
hololeap pushed a commit to hololeap/cabal that referenced this issue Apr 24, 2022
@kindaro
Copy link

kindaro commented Oct 3, 2022

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.

@Mikolaj
Copy link
Member

Mikolaj commented Oct 24, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants