Skip to content

Show unrecognized arguments error using subparser#2029

Merged
victorlin merged 2 commits into
masterfrom
victorlin/improve-errors
Jul 16, 2026
Merged

Show unrecognized arguments error using subparser#2029
victorlin merged 2 commits into
masterfrom
victorlin/improve-errors

Conversation

@victorlin

@victorlin victorlin commented Jul 15, 2026

Copy link
Copy Markdown
Member

Description of proposed changes

This PR contains 1 prep commit + 1 main commit. Message from main commit:

Standard argparse behavior always uses the top-level parser for unrecognized arguments, rendering generic error messages.

Call parse_known_args() ourselves to access the unrecognized arguments, and make the subparser accessible as an attribute on the on the parsed arguments namespace to use it for errors.

An alternative approach is to subclass _SubParsersAction, but this requires manually injecting the custom action class into every nested parser (curate, export, titers, etc.). The current approach cleanly supports nested parsers.

Related issue(s)

Closes #2028

Checklist

  • Automated checks pass
  • Check if you need to add a changelog message
  • Check if you need to add tests tested manually. I don't think this needs any command-specific functional test as argparse output may change over time.
  • Check if you need to update docs
  • Post-merge: consider applying to Nextstrain CLI too

command_attribute has a truthy default value, and there are no callers
that set a falsy value. Removing for simplicity.
@victorlin victorlin self-assigned this Jul 15, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.25%. Comparing base (c2768dd) to head (fc95052).

Files with missing lines Patch % Lines
augur/__init__.py 37.50% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2029      +/-   ##
==========================================
- Coverage   73.27%   73.25%   -0.02%     
==========================================
  Files          86       86              
  Lines       10748    10755       +7     
  Branches     2095     2096       +1     
==========================================
+ Hits         7876     7879       +3     
- Misses       2498     2502       +4     
  Partials      374      374              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread augur/__init__.py Outdated

@joverlee521 joverlee521 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I always thought it was weird that the error didn't point to the subcommand.

Comment thread augur/__init__.py Outdated
Standard argparse behavior always uses the top-level parser for
unrecognized arguments, rendering generic error messages.

Call parse_known_args() ourselves to access the unrecognized arguments,
and make the subparser accessible as an attribute on the on the parsed
arguments namespace to use it for errors.

An alternative approach is to subclass _SubParsersAction, but this
requires manually injecting the custom action class into every nested
parser (curate, export, titers, etc.). The current approach cleanly
supports nested parsers.
@victorlin victorlin force-pushed the victorlin/improve-errors branch from 8f4f9de to fc95052 Compare July 16, 2026 16:50
@victorlin victorlin merged commit c8cc27c into master Jul 16, 2026
35 checks passed
@victorlin victorlin deleted the victorlin/improve-errors branch July 16, 2026 17:20
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.

Improve error message for unrecognized arguments

2 participants