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

cli: improve messaging around usage errors #2854

Closed
abn opened this issue Aug 25, 2020 · 4 comments · Fixed by #5766
Closed

cli: improve messaging around usage errors #2854

abn opened this issue Aug 25, 2020 · 4 comments · Fixed by #5766
Labels
area/ux Features and improvements related to the user experience kind/enhancement Not a bug or feature, but improves usability or performance

Comments

@abn
Copy link
Member

abn commented Aug 25, 2020

Right now if a cli user accidentally adds a wrong option or provides an incorect value, the error with the stack trace is ... rather intimidating. This should be improved by displaying a more useful message. The change actually might be required in clikit unfortunately.

$ poetry --vers

[NoSuchOptionException]
The "--vers" option does not exist.

Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/clikit/console_application.py", line 123, in run
    io = io_factory(
  File "/home/user/.local/lib/python3.8/site-packages/poetry/console/config/application_config.py", line 168, in create_io
    resolved_command = application.resolve_command(args)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/console_application.py", line 110, in resolve_command
    return self._config.command_resolver.resolve(args, self)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/resolver/default_resolver.py", line 43, in resolve
    result = self.process_default_commands(args, application.default_commands)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/resolver/default_resolver.py", line 104, in process_default_commands
    if resolved_command.is_parsable():
  File "/home/user/.local/lib/python3.8/site-packages/clikit/resolver/resolve_result.py", line 43, in is_parsable
    self._parse()
  File "/home/user/.local/lib/python3.8/site-packages/clikit/resolver/resolve_result.py", line 49, in _parse
    self._parsed_args = self._command.parse(self._raw_args)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/api/command/command.py", line 113, in parse
    return self._config.args_parser.parse(args, self._args_format, lenient)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/args/default_args_parser.py", line 53, in parse
    self._parse(args, _fmt, lenient)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/args/default_args_parser.py", line 101, in _parse
    self._parse_long_option(token, tokens, fmt, lenient)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/args/default_args_parser.py", line 247, in _parse_long_option
    self._add_long_option(name, None, tokens, fmt, lenient)
  File "/home/user/.local/lib/python3.8/site-packages/clikit/args/default_args_parser.py", line 300, in _add_long_option
    raise NoSuchOptionException(name)
@abn abn added kind/enhancement Not a bug or feature, but improves usability or performance Good First Issue area/ux Features and improvements related to the user experience labels Aug 25, 2020
@cdeler
Copy link

cdeler commented Sep 14, 2020

@abn I found the way how to suppress the error, i.e. make it nicer:

(poetry) sergei.krotov ~/workspace/skv/poetry % poetry run poetry --vers

  Stack trace:

  1  ~/.pyenv/versions/3.8.5/envs/poetry/lib/python3.8/site-packages/clikit/console_application.py:123 in run
     io = io_factory(

  PoetryException

  The "--vers" option does not exist.

  at poetry/console/config/application_config.py:234 in create_io
      230│
      231│             new_ex = PoetryException(str(ex))
      232│             new_ex.__cause__ = None
      233│             new_ex.__suppress_context__ = True
    → 234│             raise new_ex
      235│
      236│         # If the current command is the run one, skip option
      237│         # check and interpret them as part of the executed command
      238│         if resolved_command.command.name == "run":

I suppress the exception context like raise ... from None (some sort of that as this feature was introduces in python3.3)

Is it what you wanted?

@david-fortini
Copy link
Contributor

is this still open?

@kkirsche
Copy link
Contributor

kkirsche commented Jul 30, 2021

Beyond the traceback and whatnot, would this be an area that a fuzzy comparison or a SOUNDEX implementation (EDIT: maybe Levenshtein distance makes more sense than SOUNDEX in this context) could/should be used to find options that are most like what was given to provide a "did you mean" style feature?

Copy link

github-actions bot commented Mar 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/ux Features and improvements related to the user experience kind/enhancement Not a bug or feature, but improves usability or performance
Projects
None yet
4 participants