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 UsageError exception when unsupported command is provided #110

Open
aittalam opened this issue Nov 18, 2023 · 1 comment
Open

Comments

@aittalam
Copy link

Hi, while developing a click-repl tool I realized that if I enter an undefined command I get a UsageError immediately after I hit the space bar. For instance:

python cli.py

<here I enter "whatever" followed by a space>

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

Exception No such command 'whatever'.
Press ENTER to continue...
> whatever

I found that surrounding this with a try, catching the exception and setting cmd to None works fine for my personal usage (i.e. it lets me write anything and returns a "no such command" error only when I hit enter), but I am not sure whether this is a desired behavior how this would impact other parts of the repl. What are your suggestions to solve this issue?

@thomask77
Copy link

Could this be a duplicate of #108 which was fixed in the merged PR #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

2 participants