-
Notifications
You must be signed in to change notification settings - Fork 26
fix: improve error messages with more context #449
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
Conversation
- InvalidFlag now includes a reason explaining why parsing failed - invalid-default-subcommand lint now lists valid subcommands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves error messages by adding contextual information to help users understand and fix parsing and validation errors.
Changes:
- Enhanced
InvalidFlagerror with structured fields and descriptive reasons for parsing failures - Updated lint error message for invalid default subcommands to include a list of valid subcommands
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/src/error.rs | Restructured InvalidFlag error variant from tuple to struct with token and reason fields |
| lib/src/spec/flag.rs | Updated flag parsing to use new InvalidFlag structure with context-specific error reasons |
| cli/src/cli/lint.rs | Enhanced default subcommand validation message to list valid subcommands or indicate when none exist |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| reason: "short flags must be a single character (use -- for long flags)" | ||
| .to_string(), |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string literal is split across two lines unnecessarily. Consider moving the .to_string() call to the same line as the string literal or keeping the entire statement on one line for better readability.
| reason: "short flags must be a single character (use -- for long flags)" | |
| .to_string(), | |
| reason: "short flags must be a single character (use -- for long flags)".to_string(), |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #449 +/- ##
==========================================
- Coverage 47.36% 44.81% -2.55%
==========================================
Files 47 47
Lines 6653 7145 +492
Branches 6653 7145 +492
==========================================
+ Hits 3151 3202 +51
- Misses 1739 1992 +253
- Partials 1763 1951 +188 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The InvalidFlag struct variant's fields are read by thiserror/miette derive macros, but clippy doesn't recognize the attribute usage as a "read". Add #[allow(unused_assignments)] to the error module. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
### 🚀 Features - **(lint)** add more lint checks by [@jdx](https://github.com/jdx) in [#446](#446) - add logo to docs site by [@jdx](https://github.com/jdx) in [#442](#442) - add VT323 retro terminal font and --usage branding by [@jdx](https://github.com/jdx) in [#443](#443) - add missing builder methods by [@jdx](https://github.com/jdx) in [#444](#444) ### 🐛 Bug Fixes - use pithy LLM-generated title for GitHub releases by [@jdx](https://github.com/jdx) in [#441](#441) - replace unwrap calls with proper error handling in fig.rs by [@jdx](https://github.com/jdx) in [#454](#454) - improve error messages with more context by [@jdx](https://github.com/jdx) in [#449](#449) - skip powershell test if pwsh is not installed by [@jdx](https://github.com/jdx) in [#457](#457) - match completion prefix against unescaped names by [@ilyagr](https://github.com/ilyagr) in [#460](#460) ### 🚜 Refactor - simplify Spec::merge with local macros by [@jdx](https://github.com/jdx) in [#451](#451) ### 📚 Documentation - add CLAUDE.md for Claude Code guidance by [@jdx](https://github.com/jdx) in [#452](#452) - escape generic type parameters in macro doc comments by [@jdx](https://github.com/jdx) in [#453](#453) - add rustdoc for public API functions by [@jdx](https://github.com/jdx) in [#450](#450) - add documentation to public API structs by [@jdx](https://github.com/jdx) in [#455](#455) - add conventional commit guidance to CLAUDE.md by [@jdx](https://github.com/jdx) in [#459](#459) ### ⚡ Performance - remove unnecessary clone in set_subcommand_ancestors by [@jdx](https://github.com/jdx) in [#448](#448) ### 🧪 Testing - add test coverage for untested modules by [@jdx](https://github.com/jdx) in [#447](#447) ### 🔍 Other Changes - remove commented-out trait implementations in mount.rs by [@jdx](https://github.com/jdx) in [#445](#445) - make codecov checks informational by [@jdx](https://github.com/jdx) in [#456](#456) ### 📦️ Dependency Updates - lock file maintenance by [@renovate[bot]](https://github.com/renovate[bot]) in [#439](#439) ### New Contributors - @ilyagr made their first contribution in [#460](#460)
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [usage](https://github.com/jdx/usage) | minor | `2.13.1` → `2.15.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>jdx/usage (usage)</summary> ### [`v2.15.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#2150---2026-01-26) [Compare Source](jdx/usage@v2.14.0...v2.15.0) ##### 🚀 Features - **(parse)** add Parser builder for custom env var handling by [@​jdx](https://github.com/jdx) in [#​464](jdx/usage#464) ##### 🧪 Testing - **(cli)** use fish output format for cleaner assertions by [@​ilyagr](https://github.com/ilyagr) in [#​461](jdx/usage#461) ##### 🔍 Other Changes - add cargo-semver-checks to detect breaking changes by [@​jdx](https://github.com/jdx) in [#​463](jdx/usage#463) ### [`v2.14.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#2140---2026-01-26) [Compare Source](jdx/usage@v2.13.1...v2.14.0) ##### 🚀 Features - **(lint)** add more lint checks by [@​jdx](https://github.com/jdx) in [#​446](jdx/usage#446) - add logo to docs site by [@​jdx](https://github.com/jdx) in [#​442](jdx/usage#442) - add VT323 retro terminal font and --usage branding by [@​jdx](https://github.com/jdx) in [#​443](jdx/usage#443) - add missing builder methods by [@​jdx](https://github.com/jdx) in [#​444](jdx/usage#444) ##### 🐛 Bug Fixes - use pithy LLM-generated title for GitHub releases by [@​jdx](https://github.com/jdx) in [#​441](jdx/usage#441) - replace unwrap calls with proper error handling in fig.rs by [@​jdx](https://github.com/jdx) in [#​454](jdx/usage#454) - improve error messages with more context by [@​jdx](https://github.com/jdx) in [#​449](jdx/usage#449) - skip powershell test if pwsh is not installed by [@​jdx](https://github.com/jdx) in [#​457](jdx/usage#457) - match completion prefix against unescaped names by [@​ilyagr](https://github.com/ilyagr) in [#​460](jdx/usage#460) ##### 🚜 Refactor - simplify Spec::merge with local macros by [@​jdx](https://github.com/jdx) in [#​451](jdx/usage#451) ##### 📚 Documentation - add CLAUDE.md for Claude Code guidance by [@​jdx](https://github.com/jdx) in [#​452](jdx/usage#452) - escape generic type parameters in macro doc comments by [@​jdx](https://github.com/jdx) in [#​453](jdx/usage#453) - add rustdoc for public API functions by [@​jdx](https://github.com/jdx) in [#​450](jdx/usage#450) - add documentation to public API structs by [@​jdx](https://github.com/jdx) in [#​455](jdx/usage#455) - add conventional commit guidance to CLAUDE.md by [@​jdx](https://github.com/jdx) in [#​459](jdx/usage#459) ##### ⚡ Performance - remove unnecessary clone in set\_subcommand\_ancestors by [@​jdx](https://github.com/jdx) in [#​448](jdx/usage#448) ##### 🧪 Testing - add test coverage for untested modules by [@​jdx](https://github.com/jdx) in [#​447](jdx/usage#447) ##### 🔍 Other Changes - remove commented-out trait implementations in mount.rs by [@​jdx](https://github.com/jdx) in [#​445](jdx/usage#445) - make codecov checks informational by [@​jdx](https://github.com/jdx) in [#​456](jdx/usage#456) ##### 📦️ Dependency Updates - lock file maintenance by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​439](jdx/usage#439) ##### New Contributors - [@​ilyagr](https://github.com/ilyagr) made their first contribution in [#​460](jdx/usage#460) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45MC4wIiwidXBkYXRlZEluVmVyIjoiNDIuOTIuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
Summary
InvalidFlagnow includes a reason explaining why parsing failed:invalid-default-subcommandlint now lists valid subcommands🤖 Generated with Claude Code
Note
Improves error clarity in CLI usage parsing and linting.
UsageErr::InvalidFlagto a struct variant withtoken,reason, labeledspan, and fullinput, producing messages likeInvalid flag{token}: {reason}SpecFlag::from_strto return detailed reasons for parse failures (e.g., multi-char short flags, unexpected tokens) using the newInvalidFlagfieldsinvalid-default-subcommandlint to append a list of valid subcommands (or note none are defined)#[allow(unused_assignments)]toerrormodule export to appease derive usage of struct fieldsWritten by Cursor Bugbot for commit 1bc558b. This will update automatically on new commits. Configure here.