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

The call stack is displayed when an exception is returned when an invalid parameter is displayed during command line association. #2853

Open
sunnyozj opened this issue Feb 5, 2025 · 2 comments

Comments

@sunnyozj
Copy link

sunnyozj commented Feb 5, 2025

def resolve_command(
self, ctx: Context, args: list[str]
) -> tuple[str | None, Command | None, list[str]]:
cmd_name = make_str(args[0])
original_cmd_name = cmd_name

    # Get the command
    cmd = self.get_command(ctx, cmd_name)

when get_command return ctx.fail,he call stack is displayed

Traceback (most recent call last):
File "/usr/local/bin/config", line 8, in
sys.exit(config())
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 777, in main
_bashcomplete(self, prog_name, complete_var)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 72, in _bashcomplete
if bashcomplete(cmd, prog_name, complete_var, complete_instr):
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 373, in bashcomplete
return do_complete(cli, prog_name, shell == "zsh")
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 334, in do_complete
for item in get_choices(cli, prog_name, args, incomplete):
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 282, in get_choices
ctx = resolve_ctx(cli, prog_name, args)
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 122, in resolve_ctx
cmd_name, cmd, args = ctx.command.resolve_command(ctx, args)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1297, in resolve_command
cmd = self.get_command(ctx, cmd_name)
File "/usr/local/lib/python3.9/site-packages/utilities_common/cli.py", line 102, in get_command
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 550, in fail
raise UsageError(message, self)
click.exceptions.UsageError: Too many matches: inner-congested-bw-threshold, inner-full-notify-interval, inner-ldh-threshold, inner-notify-interval

Can only the error message be retained and the call stack is not printed?

Environment:

  • Python version: 3.9
  • Click version: 7.1.2
@Rowlando13
Copy link
Collaborator

Seems like spam since your github is only 2 days old. Can you reply with some more details so I know its legit.

@sunnyozj
Copy link
Author

sunnyozj commented Feb 7, 2025

We use the click component. If the previous parameter of the command line is not completely written and multiple parameters can be matched, for example, the command line "show i ", i can match parameters such as ip and interface, and then press Tab to associate the next parameter, the command line will display the call stack.

example:
adminadmin@sonic:~# show i Traceback (most recent call last):
File "/usr/local/bin/show", line 8, in
sys.exit(cli())
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 777, in main
_bashcomplete(self, prog_name, complete_var)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 72, in _bashcomplete
if bashcomplete(cmd, prog_name, complete_var, complete_instr):
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 373, in bashcomplete
return do_complete(cli, prog_name, shell == "zsh")
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 334, in do_complete
for item in get_choices(cli, prog_name, args, incomplete):
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 282, in get_choices
ctx = resolve_ctx(cli, prog_name, args)
File "/usr/local/lib/python3.9/site-packages/click/_bashcomplete.py", line 122, in resolve_ctx
cmd_name, cmd, args = ctx.command.resolve_command(ctx, args)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1297, in resolve_command
cmd = self.get_command(ctx, cmd_name)
File "/usr/local/lib/python3.9/site-packages/utilities_common/cli.py", line 161, in get_command
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 550, in fail
raise UsageError(message, self)
click.exceptions.UsageError: Too many matches: interfaces, ip, ipv6

Can only the error message be retained and the call stack is not printed?

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