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

Special case enum option parse failures. #12281

Merged
merged 1 commit into from
Jul 12, 2021
Merged

Conversation

jsirois
Copy link
Contributor

@jsirois jsirois commented Jul 5, 2021

Display the valid choices to be more helpful. Also eliminate an unuseful
traceback from the option parse error message which always points to the
same internal option parsing code call stack.

Fixes #12277

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

Display the valid choices to be more helpful. Also eliminate an unuseful
traceback from the option parse error message which always points to the
same internal option parsing code call stack.

Fixes pantsbuild#12277

[ci skip-rust]
[ci skip-build-wheels]
@jsirois
Copy link
Contributor Author

jsirois commented Jul 5, 2021

Before:

$ ./pants dependencies --no-print-stacktrace --type=x src/python/pants/util/::
21:48:50.98 [ERROR] Error computing value for --type in scope 'dependencies' (may also be from PANTS_* environment variables).
Caused by:
ValueError: 'x' is not a valid DependencyType

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/option/parser.py", line 582, in to_value_type
    return type_arg(val_str)
  File "/usr/lib/python3.7/enum.py", line 315, in __call__
    return cls.__new__(cls, value)
  File "/usr/lib/python3.7/enum.py", line 569, in __new__
    raise exc
  File "/usr/lib/python3.7/enum.py", line 553, in __new__
    result = cls._missing_(value)
  File "/usr/lib/python3.7/enum.py", line 582, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 'x' is not a valid DependencyType

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/option/parser.py", line 284, in parse_args
    dest, kwargs, flag_vals, parse_args_request.passthrough_args
  File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/option/parser.py", line 673, in _compute_value
    flag_vals = [to_value_type(expand(x)) for x in flag_val_strs]
  File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/option/parser.py", line 673, in <listcomp>
    flag_vals = [to_value_type(expand(x)) for x in flag_val_strs]
  File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/option/parser.py", line 617, in to_value_type
    return self.to_value_type(val_str, type_arg, member_type, dest)
  File "/home/jsirois/dev/pantsbuild/pants/src/python/pants/option/parser.py", line 585, in to_value_type
    f"Error applying type '{type_arg.__name__}' to option value '{val_str}', "
pants.option.errors.ParseError: Error applying type 'DependencyType' to option value 'x', for option '--type' in scope 'dependencies': 'x' is not a valid DependencyType


(Use --print-stacktrace for more error details and/or --no-process-execution-local-cleanup to inspect chroots and/or -ldebug for more logs. See https://www.pantsbuild.org/v2.6/docs/troubleshooting for common issues. Consider reaching out for help: https://www.pantsbuild.org/v2.6/docs/getting-help.)

After:

$ ./pants dependencies --no-print-stacktrace --type=x src/python/pants/util/::
21:48:29.31 [ERROR] Error computing value for --type in scope 'dependencies' (may also be from PANTS_* environment variables).
Caused by:
Invalid choice 'x'. Choose from: source, 3rdparty, source-and-3rdparty


(Use --print-stacktrace for more error details and/or --no-process-execution-local-cleanup to inspect chroots and/or -ldebug for more logs. See https://www.pantsbuild.org/v2.6/docs/troubleshooting for common issues. Consider reaching out for help: https://www.pantsbuild.org/v2.6/docs/getting-help.)

@jsirois jsirois requested review from Eric-Arellano and benjyw July 5, 2021 04:53
Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks, John!

@jsirois jsirois merged commit b8f6b9f into pantsbuild:main Jul 12, 2021
@jsirois jsirois deleted the issues/12277 branch July 12, 2021 18:55
@wisechengyi wisechengyi mentioned this pull request Jul 17, 2021
wisechengyi added a commit that referenced this pull request Jul 17, 2021
### Internal

* [internal] Manually fix Black lockfile to handle interpreter constraints ([#12366](#12366))
* Revert "Prefix the entire setup.py chroot. (#12359)" ([#12370](#12370))
* [internal] Cache native client binary in CI ([#12355](#12355))
* Prefix the entire setup.py chroot. ([#12359](#12359))
* [internal] Fix AWS CLI breaking due to Python 2 usage ([#12364](#12364))
* [Internal] Add `git_url()` helper to `docutil.py` ([#12352](#12352))
* [Internal] Refactor how `PythonToolBase` exposes requirements and interpreter constraints ([#12356](#12356))
* [internal] Add experimental per-tool lockfiles with Docformatter as an example ([#12346](#12346))
* Remove Pants's dpeendency on `requests` ([#12348](#12348))
* [internal] Remove `TwoStepPex` abstraction ([#12343](#12343))
* Add psycopg2-binary to default module mapping ([#12339](#12339))
* [internal] Upgrade toolchain pants plugin to 0.13.1 ([#12338](#12338))
* Add an API to coarsen/partition Targets by their cycles ([#12251](#12251))
* Prepare 2.5.1 ([#12329](#12329))
* Bootstrap fewer JVM versions in Coursier/javac tests to hopefully reduce CI flakiness ([#12325](#12325))
* Native client respects `--concurrent`. ([#12324](#12324))
* Add client lib tests. ([#12322](#12322))
* Special case enum option parse failures. ([#12281](#12281))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid option enum values lead to parse error that does not list valid choices.
3 participants