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 on invalid -//foo and -@repo//foo options #16563

Closed
wants to merge 1 commit into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Oct 26, 2022

-//foo and -@repo//foo are always invalid Bazel options, but are usually meant to be either negative target patterns (which have to come after the -- separator) or Starlark options (which always start with --).

With this commit, the error shown to the user mentions these two situations and how to fix the issue in each case.

@fmeum fmeum marked this pull request as ready for review October 26, 2022 15:12
@fmeum
Copy link
Collaborator Author

fmeum commented Oct 26, 2022

@aranguyen Could you review this PR?

@michajlo
Copy link
Contributor

Is there any more discussion around this and why putting the patterns after -- isn't sufficient?

@fmeum
Copy link
Collaborator Author

fmeum commented Oct 26, 2022

Is there any more discussion around this and why putting the patterns after -- isn't sufficient?

It's sufficient if you know about it, but the error message you get if you don't doesn't give any indication of this being how to fix your command line. Instead of catching this case and emitting a more helpful error message, it seemed simpler to just make the most common, unambiguous case work out of the box.

I don't have more context than https://github.com/CodeIntelligenceTesting/cifuzz/pull/383#discussion_r1005694516 and similar past experiences that myself or coworkers had with this limitation.

Given his reaction to the PR, maybe @brentleyjones can provide a separate opinion.

@brentleyjones
Copy link
Contributor

I've just run into the same situation myself, and agree that it's hard to know when you need --, and if we can make this work without it 👍.

@fmeum fmeum force-pushed the fix-negative-target-pattern branch from 5a8944c to f50af3b Compare October 26, 2022 18:09
@michajlo
Copy link
Contributor

IIUC this is a quite common convention for CLI tools, and while it is confusing I fear changing things will only move confusion around, not reduce it. The one example that I believe is cited in the code comments is that relative labels (which I personally use more often) behave differently. It's also liable to cause confusion around starlark-defined flags, which can look like target patterns but are indeed flags.

My interest here is keeping command-line parsing semantics as tight as possible so that any attempted automated introspection of command lines doesn't need to be too smart.

@fmeum
Copy link
Collaborator Author

fmeum commented Oct 26, 2022

I agree that not supporting all negative target patterns has potential to create confusion in different places and that supporting any kind of new syntax will make command line parsing more difficult.

Starlark flags shouldn't add to the confusion though as they always starts with two dashes whereas negative target patterns start with one - isn't that a clean separation?

Given that, would you support a version of this PR that doesn't add support for absolute negative target patterns without a --, but instead fails with a more descriptive error?

@michajlo
Copy link
Contributor

Starlark flags shouldn't add to the confusion though as they always starts with two dashes whereas negative target patterns start with one - isn't that a clean separation?

I'm thinking of how one might be tricked into thinking -//foo is a valid syntax because the parser accepted it, or typo-ing -//foo and not noticing because the parser accepted it.

Given that, would you support a version of this PR that doesn't add support for absolute negative target patterns without a --, but instead fails with a more descriptive error?

As long as it can be done tastefully sure. Thought it may not be me stamping it, I'm mainly here because I have an interest in parsing semantics.

@ShreeM01 ShreeM01 added team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Oct 26, 2022
@aranguyen
Copy link
Contributor

@fmeum Thank you very much for sending the PR. I just had the sync with the team and brought up your PR. We agree with #16563 (comment) and will be supportive of reviewing another PR that shows a more descriptive error.

`-//foo` and `-@repo//foo` are always invalid Bazel options, but are
usually meant to be either negative target patterns (which have to come
after the `--` separator) or Starlark options (which always start with
`--`).

With this commit, the error shown to the user mentions these two
situations and how to fix the issue in each case.
@fmeum fmeum force-pushed the fix-negative-target-pattern branch from f50af3b to 81b8589 Compare October 30, 2022 09:04
@fmeum fmeum changed the title Allow absolute negative target patterns without a -- separator Improve error on invalid -//foo and -@repo//foo options Oct 30, 2022
@fmeum
Copy link
Collaborator Author

fmeum commented Oct 30, 2022

@aranguyen I updated the commit and the PR description, please take another look.

@aranguyen aranguyen self-assigned this Oct 31, 2022
Copy link
Contributor

@aranguyen aranguyen left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@aranguyen aranguyen added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Nov 7, 2022
@copybara-service copybara-service bot closed this in 48efe73 Nov 8, 2022
@sgowroji sgowroji removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Nov 8, 2022
@fmeum fmeum deleted the fix-negative-target-pattern branch November 8, 2022 14:25
@iancha1992
Copy link
Member

@bazel-io fork 6.3.0

iancha1992 pushed a commit to iancha1992/bazel that referenced this pull request May 26, 2023
`-//foo` and `-@repo//foo` are always invalid Bazel options, but are usually meant to be either negative target patterns (which have to come after the `--` separator) or Starlark options (which always start with `--`).

With this commit, the error shown to the user mentions these two situations and how to fix the issue in each case.

Closes bazelbuild#16563.

PiperOrigin-RevId: 486920951
Change-Id: I9390d3859aa62c2b67eac05cb96a06209a9b7c36
iancha1992 added a commit that referenced this pull request Jun 1, 2023
`-//foo` and `-@repo//foo` are always invalid Bazel options, but are usually meant to be either negative target patterns (which have to come after the `--` separator) or Starlark options (which always start with `--`).

With this commit, the error shown to the user mentions these two situations and how to fix the issue in each case.

Closes #16563.

PiperOrigin-RevId: 486920951
Change-Id: I9390d3859aa62c2b67eac05cb96a06209a9b7c36

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Configurability platforms, toolchains, cquery, select(), config transitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants