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

Better error message when an address does not exist #15788

Merged
merged 7 commits into from
Jun 9, 2022

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Jun 8, 2022

Part of #14468.

Before:

❯ ./pants list src/python/pants/util:fake
ResolveError: 'fake' was not found in namespace 'src/python/pants/util'. Did you mean one of:
  :tests
  :util
❯ ./pants list src/python/pants/util:fake
  ValueError: The address `3rdparty/python#bad` was not generated by the target `3rdparty/python:python`, which only generated these addresses:

  * 3rdparty/python:python
  * 3rdparty/python#PyYAML
  * 3rdparty/python#ansicolors

Did you mean to use one of those addresses?

After:

❯ ./pants list src/python/pants/util:fake
ResolveError: The address src/python/pants/util:fake from CLI arguments does not exist.

The target name ':fake' is not defined in the directory src/python/pants/util. Did you mean one of these target names?

  * :tests
  * :util
❯ ./pants list 3rdparty/python#bad
ResolveError: The address `3rdparty/python#bad` from CLI arguments was not generated by the target `3rdparty/python:python`. Did you mean one of these addresses?

  * 3rdparty/python:python
  * 3rdparty/python#PyYAML
  * 3rdparty/python#ansicolors

[ci skip-rust]
[ci skip-build-wheels]

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
src/python/pants/base/exceptions.py Outdated Show resolved Hide resolved
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Eric-Arellano added a commit that referenced this pull request Jun 8, 2022
…h.address` (#15790)

This avoids a cyclical import with #15788.

[ci skip-rust]
[ci skip-build-wheels]
…s-error

# Conflicts:
#	src/python/pants/base/exceptions.py

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano requested a review from stuhood June 9, 2022 03:36
Copy link
Member

@kaos kaos left a comment

Choose a reason for hiding this comment

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

I think this improves the situation.

However, the origin description "CLI arguments" is a little bit risky. From my experience, it was rather confusing when that origin description was used for the --changed-since option, as the unknown things technically didn't come from the CLI arguments then.

Just something to keep in mind, that we should be really sure that the origin is accurate at all times, or we'll send users off in the wrong direction hunting for issues. And there is something worse than no information, and that is wrong information.

{namespace}. Did you mean one of these target names?\n
"""
+ bullet_list(f":{name}" for name in known_names)
)
Copy link
Member

Choose a reason for hiding this comment

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

I prefer the other way to formulate this. That is, simply state the known target names and leave the question of the message.

{bullet_list(str(t.address) for t in parametrizations.all)}\n\n
Did you mean to use one of those addresses?
"""
)
Copy link
Member

Choose a reason for hiding this comment

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

This is the other way to formulate this, and this way is the one I prefer. More importantly though is to be consistent, either use "did you mean?" or "these are the known things: ...".

Oh, and now I noticed the "did you mean?" question at the end of the list. That is perfectly fine, and one of the issues I initially had in the first comment that the question was posed as "did you mean of these?" before presenting what the options were..

Copy link
Member

Choose a reason for hiding this comment

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

Ah, and the reason is that I based my comments on what I read in the PR description, which now is out of date with the code... :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on your feedback, I made things consistent for both error messages. Thanks!

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano
Copy link
Contributor Author

However, the origin description "CLI arguments" is a little bit risky. From my experience, it was rather confusing when that origin description was used for the --changed-since option, as the unknown things technically didn't come from the CLI arguments then.

Agreed. That was before #15730. We were lying and hardcoding the description_of_origin as always being "CLI arguments" even when it was not.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Copy link
Member

@kaos kaos left a comment

Choose a reason for hiding this comment

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

Nice. Consistency ftw.

@Eric-Arellano Eric-Arellano merged commit 1e06f67 into pantsbuild:main Jun 9, 2022
@Eric-Arellano Eric-Arellano deleted the better-address-error branch June 9, 2022 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants