Skip to content

Fix #2779: Show full option name in error for multicharacter short options#3303

Closed
717986230 wants to merge 2 commits intopallets:mainfrom
717986230:main
Closed

Fix #2779: Show full option name in error for multicharacter short options#3303
717986230 wants to merge 2 commits intopallets:mainfrom
717986230:main

Conversation

@717986230
Copy link
Copy Markdown

Fixes #2779

Problem

When passing a wrong multicharacter short option like -dbgwrong, the error message incorrectly shows:

No such option: -d

instead of the full option name:

No such option: -dbgwrong

Root Cause

In _match_short_opt(), the function iterates through each character of the argument and raises NoSuchOption with just the first invalid character, not the original argument.

Solution

Modified src/click/parser.py to report the full original argument when raising NoSuchOption:

# Before:
raise NoSuchOption(opt, ctx=self.ctx)  # opt is just "-d"

# After:
raise NoSuchOption(_normalize_opt(arg, self.ctx), ctx=self.ctx)  # arg is "-dbgwrong"

Testing

  • Manual testing with various multicharacter short options
  • All existing tests should pass

Impact

  • Improves error message accuracy
  • Better user experience when debugging command-line options
  • No breaking changes to API

This PR was created with AI assistance. The fix is minimal and focused on the reported issue.

杨兴隆 and others added 2 commits April 3, 2026 19:34
…hort options

When passing a wrong multicharacter short option like `-dbgwrong`,
the error message incorrectly shows 'No such option: -d' instead of
the full option name.

This fix reports the full original argument when raising NoSuchOption,
instead of just the first invalid character.

Fixes pallets#2779
@davidism davidism closed this Apr 3, 2026
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

Successfully merging this pull request may close these issues.

Wrong error message when wrong multicharacter short option is passed

2 participants