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

Improve error message when multiple .cabal files are in the same directory #7396

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented May 15, 2021

closes #7395


Please include the following checklist in your PR:

@fendor
Copy link
Collaborator Author

fendor commented May 15, 2021

Going to improve the error message as soon as I understood what the KnownPackages actually represent.

@jneira
Copy link
Member

jneira commented Jun 15, 2021

@fendor i guess your knowledge about KnownPackages has improved 😉
This a nice improvement in an area that needs to be imrpoved a lot

@jneira
Copy link
Member

jneira commented Nov 13, 2021

any chance to make definitive the pr?

@jneira jneira added the re: error-message Concerning error messages delivered to the user label Nov 13, 2021
@fendor
Copy link
Collaborator Author

fendor commented Nov 13, 2021

Unfortunately, changing this requires a bit more refactoring than hoped...

From KnownPackages, we can obtain the .cabal filepath, but cabal resolves somewhat weird:

Error: cabal: Multiple packages have been found:
multiple-cabal-files-0.1.0.0 defined in: "./multiple-cabal-files.cabal"
multiple-cabal-files-0.1.0.0 defined in: "./multiple-cabal-files.cabal"

Although the latter is defined in another cabal file named multiple-cabal-files2.cabal. Makes you wonder why cabal fails at all.

@fendor
Copy link
Collaborator Author

fendor commented Nov 13, 2021

I have a fix now, but it feels slightly brittle. We need a better strategy to track where a package originates from...

@fendor fendor changed the title Draft: Improve error message when multiple .cabal files are in the same directory Improve error message when multiple .cabal files are in the same directory Nov 13, 2021
@jneira
Copy link
Member

jneira commented Nov 14, 2021

We need a better strategy to track where a package originates from...

Yeah, i think we are not tracking enough information in types across the different build phases. The use of monoids in the config f.e. causes a form of "monoid blindness` and we are losing the origin of each value. If phases, along with its inputs and outputs would be encoded in types keeping their sources until the end i think we could improve error messages and make some bugs harder to arise.

There would be a Config Global a Config Cli, a Config ProjectFile and the final monoid folding should be done on the fly, without losing the info of where each value was defined.

@fendor
Copy link
Collaborator Author

fendor commented Nov 14, 2021

Just typing these are probably not enough. It still seems like monkey patching, even if we track the provenancen of FieldDescr entries for this specific issue.

@gbaz
Copy link
Collaborator

gbaz commented Feb 11, 2022

I think this suffice for now as a clear improvement, and if you resolve the conflicts I think we should seek more reviews and merge.

Comment on lines 27 to 29
-- | An unpacked package in the given dir, or current dir,
-- with the given .cabal file name within the given dir.
-- If Nothing, this will default to @'PackageId' <.> "cabal"@.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like someone had a stroke while writing this comment.

@fendor
Copy link
Collaborator Author

fendor commented Feb 13, 2022

I currently do not understand why the test has changed, while it might be benign, I would like to understand why we resolve to a different target now.

@fendor fendor force-pushed the polish/7395 branch 2 times, most recently from 0c87ca2 to 43dbb04 Compare February 19, 2022 10:34
Comment on lines +2 to +3
-- Test that we can resolve a module name ambiguity when reexporting
-- by explicitly specifying what package we want.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- Test that we can resolve a module name ambiguity when reexporting
-- by explicitly specifying what package we want.

@fendor
Copy link
Collaborator Author

fendor commented Feb 19, 2022

I have no idea why the test fails... must be some tricky interaction...

@Mikolaj
Copy link
Member

Mikolaj commented Feb 19, 2022

The error is here, right?

 tests/IntegrationTests2.hs:205:
        expected: [TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing]
         but got: [TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}] Nothing,TargetComponent (PackageIdentifier {pkgName = PackageName "p", pkgVersion = mkVersion [0,1]}) (CLibName LMainLibName) (FileTarget "P"),TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetPackage TargetExplicitNamed [PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}] Nothing,TargetComponent (PackageIdentifier {pkgName = PackageName "q", pkgVersion = mkVersion [0,1]}) (CLibName LMainLibName) (FileTarget "Q")]

@Mikolaj
Copy link
Member

Mikolaj commented Feb 19, 2022

Perhaps the version is expected and should just be committed as the new results of the test? Aren't you changing just these bits of the code?

@fendor
Copy link
Collaborator Author

fendor commented Feb 19, 2022

The error is here, right?

Right

Perhaps the version is expected

As long as I don't understand why the value has changed, it is not expected.
Afaict, nothing I changed in this PR should have affected this... I had one suspicion what might have changed, but it proved to be either insufficient or not the root cause.

should just be committed as the new results of the test

Yeah, that might be the solution, but I at least would feel better if I understood the reason for the changed value.

@fendor
Copy link
Collaborator Author

fendor commented Feb 23, 2022

As it turns out, the failing test-case is genuine.

@fendor fendor force-pushed the polish/7395 branch 2 times, most recently from 6187bee to b5f73f7 Compare February 23, 2022 17:50
-- If @mCabalFile@ is 'Nothing', then the '.cabal' file can be assumed to
-- be '<package-name>.cabal'.
-- Otherwise, @mCabalFile@ points to the '.cabal' file within @directory@.
LocalUnpackedPackage FilePath (Maybe FilePath)
Copy link
Member

@jneira jneira Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a record would suppose lot of changes? field names would help a lot in understand the two params

@Mikolaj
Copy link
Member

Mikolaj commented Feb 23, 2022

How about a changelog?

@fendor
Copy link
Collaborator Author

fendor commented Feb 24, 2022

I am not sure why, but I think like my tests are not picked up by CI

@Mikolaj
Copy link
Member

Mikolaj commented Feb 24, 2022

borked rebase?

@jneira
Copy link
Member

jneira commented Feb 24, 2022

I am not sure why, but I think like my tests are not picked up by CI

cause they are succesful? they are not printed out in logs, only failed, known broken and skipped ones:

=== cabal-install: cabal-testsuite ============================= 09:28:38 ===
>>> **/cabal-tests --builddir=**/cabal-testsuite-3 --with-cabal=**/cabal -j2 --hide-successes 
threads: 2
tests to run: 306
PackageTests/NewSdist/ManyDataFiles/many-data-files.test.hs                                                       SKIP no open file limit (0.05s)
PackageTests/NewBuild/T4375/cabal.test.hs                                                                         SKIP needs ghc<8.1 (0.02s)
PackageTests/CustomPlain/cabal.test.hs                                                                            SKIP needs ghc<8.2 (0.02s)
PackageTests/CustomDep/cabal.test.hs                                                                              SKIP needs ghc<8.2 (0.02s)
PackageTests/InternalVersions/BuildToolDependsExtra/setup.test.hs                                                 OK (known failure) (0.95s)
PackageTests/InternalVersions/BuildToolsExtra/setup.test.hs                                                       OK (known failure) (0.96s)
PackageTests/InternalVersions/BuildDependsExtra/setup.test.hs                                                     OK (known failure) (0.94s)
SKIPPED 4 tests
OK

https://github.com/haskell/cabal/runs/5316369875?check_suite_focus=true

make them fail cherry picking tests in a branch based on master to check ;-)

@fendor
Copy link
Collaborator Author

fendor commented Feb 24, 2022

But the test doesn't succeed locally any more T_T I am so confused

@jneira
Copy link
Member

jneira commented Feb 24, 2022

But the test doesn't succeed locally any more T_T I am so confused

Not sure if it can help but last master workflow run has 305 tests and no 306:

=== cabal-install: cabal-testsuite ============================= 08:47:50 ===
>>> **/cabal-tests --builddir=**/cabal-testsuite-3 --with-cabal=**/cabal -j2 --hide-successes 
threads: 2
tests to run: 305
PackageTests/NewSdist/ManyDataFiles/many-data-files.test.hs                                                       SKIP no open file limit (0.04s)
PackageTests/NewBuild/T4375/cabal.test.hs                                                                         SKIP needs ghc<8.1 (0.02s)
PackageTests/CustomPlain/cabal.test.hs                                                                            SKIP needs ghc<8.2 (0.03s)
PackageTests/CustomDep/cabal.test.hs                                                                              SKIP needs ghc<8.2 (0.02s)
PackageTests/InternalVersions/BuildToolDependsExtra/setup.test.hs                                                 OK (known failure) (0.92s)
PackageTests/InternalVersions/BuildToolsExtra/setup.test.hs                                                       OK (known failure) (0.95s)
PackageTests/InternalVersions/BuildDependsExtra/setup.test.hs                                                     OK (known failure) (0.91s)
SKIPPED 4 tests
OK

https://github.com/haskell/cabal/runs/5315945053?check_suite_focus=true

@Mikolaj
Copy link
Member

Mikolaj commented Feb 24, 2022

borked local rebase?

@fendor
Copy link
Collaborator Author

fendor commented Feb 24, 2022

I rebased again to make sure, but I think everything's "in order" locally.

@ulysses4ever
Copy link
Collaborator

This looked very close to completion. @fendor how do you feel about bringing it over the line?

@fendor
Copy link
Collaborator Author

fendor commented Jul 9, 2022

Unfortunately, it is not that close, I am failing to write a proper integration test that proves that this PR actually achieves what it sets out to do.

@ulysses4ever ulysses4ever marked this pull request as draft July 10, 2022 14:53
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Sep 1, 2022
@ulysses4ever ulysses4ever removed the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: error-message Concerning error messages delivered to the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message when multiple .cabal files are in the same directory
5 participants