#2853·click

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

Author: sunnyozjCreated Feb 5, 2025Updated Aug 21, 2026
Labelsparsing
python
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

pytb
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