Skip to content

TargetSelector: Include a hint in the error message for internal error #8628

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

Merged
merged 1 commit into from
Jan 19, 2023

Conversation

lf-
Copy link
Collaborator

@lf- lf- commented Dec 6, 2022

This is a mediocre solution, and really should generate a different error entirely at an earlier stage, but I'm not familiar enough with how to achieve that and I don't think I have time at the moment.

Fixes #8484.

[nix-shell:~/co/cabal/t8484]$ cabal build lib:generic-deriving
Error: cabal: Internal error in target matching. It should always be possible
to find a syntax that's sufficiently qualified to give an unambiguous match.
However when matching 'lib:generic-deriving' we found lib:generic-deriving
(unknown-component) which does not have an unambiguous syntax. The possible
syntax and the targets they match are as follows:
'lib:generic-deriving' which matches lib:generic-deriving (unknown-component),
:pkg:lib:lib:lib:file:generic-deriving (unknown-file)


[nix-shell:~/co/cabal/t8484]$ /Users/jade/co/cabal/dist-newstyle/build/aarch64-osx/ghc-9.2.4/cabal-install-3.9.0.0/x/cabal/build/cabal/cabal build lib:generic-deriving
Warning: this is a debug build of cabal-install with assertions enabled.
Error: cabal: Internal error in target matching. It should always be possible
to find a syntax that's sufficiently qualified to give an unambiguous match.
However when matching 'lib:generic-deriving' we found lib:generic-deriving
(unknown-component) which does not have an unambiguous syntax. The possible
syntax and the targets they match are as follows:
'lib:generic-deriving' which matches lib:generic-deriving (unknown-component),
:pkg:lib:lib:lib:file:generic-deriving (unknown-file)


Hint: this may be caused by trying to build a package that exists in the
project directory but is missing from cabal.project.

Please include the following checklist in your PR:

Please also shortly describe how you tested your change. Bonus points for added tests!

@lf-
Copy link
Collaborator Author

lf- commented Dec 6, 2022

looks like the ghc 9.4.2 CI is broken unrelated to this

@Mikolaj
Copy link
Member

Mikolaj commented Dec 7, 2022

Indeed, CI was broken. Let me rebase to include the fix.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 7, 2022

@mergify rebase

@mergify
Copy link
Contributor

mergify bot commented Dec 7, 2022

rebase

✅ Branch has been successfully rebased

@Mikolaj
Copy link
Member

Mikolaj commented Dec 7, 2022

Success!

@jneira
Copy link
Member

jneira commented Jan 3, 2023

Hi, thanks for the pr. I agree this is not optimal and it does not scale if we have to list all possible causes of the error. Having only one of the possible causes will make users check it in first place for the rest of cases.

@dmwit
Copy link
Collaborator

dmwit commented Jan 15, 2023

For what it's worth, I just ran into this error, and the hint given here would have resolved my problem.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 16, 2023

Hah, so we have divergent opinions.

@jneira: any cheap constructive suggestion from you? E.g., adding a disclaimer to the hint that it's only one of possible causes?

Any other opinions, ideas, anybody?

@jneira
Copy link
Member

jneira commented Jan 16, 2023

yeah such disclaimer would be fine, good idea

@ulysses4ever
Copy link
Collaborator

I like the current state. What I'm afraid of is that the output is already very mouthful. I'm not sure many people will get to the hint. Even less so — to the disclaimer. I'd invite people to think whether we could shrink the preexisted text.

Anyway, I think this should be merged in some form; e.g. just adding a disclaimer to the current wording in the patch would work for me.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 16, 2023

So perhaps let's start with a short version of the hint and elaborate afterwards?

@lf-: your take? we'd better merge ASAP for cabal 3.10.

@lf-
Copy link
Collaborator Author

lf- commented Jan 16, 2023

So perhaps let's start with a short version of the hint and elaborate afterwards?

@lf-: your take? we'd better merge ASAP for cabal 3.10.

Thoughts on the following attempt? I can get it into code later today.

Internal error in target matching: could not make a fully qualified target selector.
We made the target 'lib:generic-deriving' that was expected to be unambiguous but matches the following targets:

  • lib:generic-deriving (unknown-component)
  • :pkg:lib:lib:lib:file:generic-deriving (unknown-file)

Note: Cabal expects to be able to make a single fully qualified name for a target
or provide a more specific error. Our failure to do so is a bug in cabal. Tracking issue: #8684

Hint: one possible cause is that a package 'generic-deriving' exists in
the project directory but isn't included in the packages stanza of your cabal project file

@lf-
Copy link
Collaborator Author

lf- commented Jan 16, 2023

several edits later, i think my rewrite of the message is at least more legible and concise. any thoughts? did i remove any info that needed to be there?

@Mikolaj
Copy link
Member

Mikolaj commented Jan 16, 2023

@dmwit: you are the positive force here: would that one be helpful to you still?

@ulysses4ever
Copy link
Collaborator

Looks like a good improvement to me, thank you!

Note: Cabal expects to be able to make a single fully qualified name for a target
or provide a more specific error. Our failure to do so is a bug in cabal.

Well, our failure to do the latter (provide a more specific error) is a bug, but the former (resolve the target) may be not. So, this phrase is a little confusing to me.

@lf-
Copy link
Collaborator Author

lf- commented Jan 16, 2023

Looks like a good improvement to me, thank you!

Note: Cabal expects to be able to make a single fully qualified name for a target
or provide a more specific error. Our failure to do so is a bug in cabal.

Well, our failure to do the latter (provide a more specific error) is a bug, but the former (resolve the target) may be not. So, this phrase is a little confusing to me.

My understanding of this error is that this error is saying "we screwed up and couldn't come up with an unambiguous qualified name for the target", which is always a bug. There's two cases:

  • We should have issued a different error earlier, and the leftovers of that mistake have caused the qualified-name logic to explode, which is a bug (I think that this is the case when we issue this error for something missing from the project file)
  • We did actually screw up coming up with a fully qualified name, and the qualified name code should have done a better job, which is also a bug, since it should always be able to come up with a qualified name

@ulysses4ever
Copy link
Collaborator

My understanding of this error is that this error is saying "we screwed up and couldn't come up with an unambiguous qualified name for the target"

Maybe I'm wrong but I think that this failure can come from the fact that the user underspecified the target. Imagine there's an executable and a test with the same name blah. Cabal will have to fail if you ask to cabal build blah, right?

@lf-
Copy link
Collaborator Author

lf- commented Jan 16, 2023

Nope, this is specifically a "we screwed up" error. That error is as follows, today:

$ cabal build joshing
Error: cabal: Ambiguous target 'joshing'. It could be:
exe:joshing (component)
lib:joshing (component)

@lf-
Copy link
Collaborator Author

lf- commented Jan 17, 2023

Alright, it looks like so:

[nix-shell:~/co/cabal/repro]$ /home/jade/co/cabal/dist-newstyle/build/x86_64-linux/ghc-9.2.4/cabal-install-3.9.0.0/x/cabal/build/cabal/cabal build lib:generic-deriving
Warning: this is a debug build of cabal-install with assertions enabled.
Error: cabal: Internal error in target matching: could not make an unambiguous
fully qualified target selector for 'lib:generic-deriving'.
We made the target 'lib:generic-deriving' (unknown-component) that was
expected to be unambiguous but matches the following targets:
'lib:generic-deriving', matching:
- lib:generic-deriving (unknown-component)
- :pkg:lib:lib:lib:file:generic-deriving (unknown-file)

Note: Cabal expects to be able to make a single fully qualified name for a
target or provide a more specific error. Our failure to do so is a bug in
cabal. Tracking issue: https://github.com/haskell/cabal/issues/8684

Hint: this may be caused by trying to build a package that exists in the
project directory but is missing from the 'packages' stanza in your cabal
project file.

@dmwit
Copy link
Collaborator

dmwit commented Jan 17, 2023

The updated error+hint looks quite approachable to me. The target name :pkg:lib:lib:lib:file:generic-deriving still kind of blows my mind -- apparently the language of targets is much richer than I knew -- but that's kinda beside the point!

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

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

I'd say, let's ship it.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 17, 2023

@lf-: please kindly set the merge_me label once you are ready.

@lf-
Copy link
Collaborator Author

lf- commented Jan 17, 2023

@lf-: please kindly set the merge_me label once you are ready.

I cannot do this because I don't have the relevant github role, but go ahead and merge :)

@Mikolaj
Copy link
Member

Mikolaj commented Jan 17, 2023

Oh, you have not accepted the invite? Whatever you prefer...

@lf- lf- added the merge me Tell Mergify Bot to merge label Jan 17, 2023
@lf-
Copy link
Collaborator Author

lf- commented Jan 17, 2023

ah my mistake, didn't see the email. done

@Mikolaj
Copy link
Member

Mikolaj commented Jan 17, 2023

Splendid. Thank you. In 2 days, it should auto-merge, unless the PR changes.

@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jan 19, 2023
This is a mediocre solution, and really should generate a different
error entirely at an earlier stage, but I'm not familiar enough with how
to achieve that.
@mergify
Copy link
Contributor

mergify bot commented Jan 19, 2023

⚠️ This pull request got rebased on behalf of a random user of the organization.
This behavior will change on the 1st February 2023, Mergify will pick the author of the pull request instead.

To get the future behavior now, you can configure bot_account options (e.g.: bot_account: { author } or update_bot_account: { author }.

Or you can create a dedicated github account for squash and rebase operations, and use it in different bot_account options.

@mergify mergify bot merged commit a78d77b into haskell:master Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Baffling error messages for a package not being included in the project file
5 participants