Skip to content

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

Description

@sunnyozj
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,the call stack is displayed

Traceback (most recent call last):
  File "/usr/local/bin/config", line 8, in <module>
    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

Activity

  1. Rowlando13 commented on Feb 7, 2025

    @Rowlando13
    Member

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

  2. sunnyozj commented on Feb 7, 2025

    @sunnyozj
    Author

    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?

  3. added
    parsingParsing, parameters, commands, chaining, context
    on Aug 8, 2026
  4. deleted a comment from Krish231204 on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parsingParsing, parameters, commands, chaining, context

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions