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

Unhandled exception in autocompletion of invalid command #108

Closed
opirko-ui opened this issue Oct 17, 2023 · 3 comments
Closed

Unhandled exception in autocompletion of invalid command #108

opirko-ui opened this issue Oct 17, 2023 · 3 comments

Comments

@opirko-ui
Copy link
Contributor

Hello,
When I write an invalid command in Click REPL - e.g. "nonsensicalcmd" the moment I press space after the command I get this:

Unhandled exception in event loop:
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/prompt_toolkit/buffer.py", line 1919, in new_coroutine
    await coroutine(*a, **kw)
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/prompt_toolkit/buffer.py", line 1743, in async_completer
    async for completion in async_generator:
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/prompt_toolkit/completion/base.py", line 323, in get_completions_async
    async for completion in completer.get_completions_async(
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/prompt_toolkit/completion/base.py", line 199, in get_completions_async
    for item in self.get_completions(document, complete_event):
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/click_repl/_completer.py", line 257, in get_completions
    self.parsed_ctx = _resolve_context(args, self.ctx)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/click_repl/utils.py", line 46, in _resolve_context
    name, cmd, args = command.resolve_command(ctx, args)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/click/core.py", line 1746, in resolve_command
    ctx.fail(_("No such command {name!r}.").format(name=original_cmd_name))
  File "/home/abc/proj/.venv/lib/python3.11/site-packages/click/core.py", line 684, in fail
    raise UsageError(message, self)

Exception No such command 'nonsensicalcmd'.
Press ENTER to continue...

I would expect that it would write nothing up until the point when I press enter, then I'd expect something like Error: No such command 'nonsensicalcmd'. (Click without REPL writes this). It is definitely odd that there's an unhandled exception.

Used versions:
click 8.1.7
click_repl 0.3.0
Python 3.11.6

@opirko-ui
Copy link
Contributor Author

Try-catch with a void return here

self.parsed_ctx = _resolve_context(args, self.ctx)
seems to resolve the issue. But that's just my naive hotfix. @auvipy ?

@auvipy
Copy link
Collaborator

auvipy commented Nov 8, 2023

you can come with a draft PR with the hotfix and some sort of unit test

@opirko
Copy link
Contributor

opirko commented Nov 9, 2023

Very well, created #109

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

No branches or pull requests

3 participants