Skip to content

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jan 19, 2026

Summary

  • InvalidFlag now includes a reason explaining why parsing failed:
    • "short flags must be a single character (use -- for long flags)"
    • "unexpected token (expected -x, --long, , or [arg])"
  • invalid-default-subcommand lint now lists valid subcommands

🤖 Generated with Claude Code


Note

Improves error clarity in CLI usage parsing and linting.

  • Refactors UsageErr::InvalidFlag to a struct variant with token, reason, labeled span, and full input, producing messages like Invalid flag {token}: {reason}
  • Updates SpecFlag::from_str to return detailed reasons for parse failures (e.g., multi-char short flags, unexpected tokens) using the new InvalidFlag fields
  • Enhances invalid-default-subcommand lint to append a list of valid subcommands (or note none are defined)
  • Adds #[allow(unused_assignments)] to error module export to appease derive usage of struct fields

Written by Cursor Bugbot for commit 1bc558b. This will update automatically on new commits. Configure here.

- InvalidFlag now includes a reason explaining why parsing failed
- invalid-default-subcommand lint now lists valid subcommands
Copilot AI review requested due to automatic review settings January 19, 2026 19:10
Copy link
Contributor

Copilot AI left a 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 InvalidFlag error 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.

Comment on lines +279 to +280
reason: "short flags must be a single character (use -- for long flags)"
.to_string(),
Copy link

Copilot AI Jan 19, 2026

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.

Suggested change
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(),

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 9.52381% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.81%. Comparing base (9df7c86) to head (1bc558b).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/spec/flag.rs 0.00% 3 Missing and 8 partials ⚠️
cli/src/cli/lint.rs 20.00% 3 Missing and 5 partials ⚠️
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.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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>
@jdx jdx merged commit ffe16d3 into main Jan 19, 2026
7 of 9 checks passed
@jdx jdx deleted the fix/improve-error-messages branch January 19, 2026 21:26
jdx pushed a commit that referenced this pull request Jan 26, 2026
### 🚀 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)
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jan 27, 2026
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 [@&#8203;jdx](https://github.com/jdx) in [#&#8203;464](jdx/usage#464)

##### 🧪 Testing

- **(cli)** use fish output format for cleaner assertions by [@&#8203;ilyagr](https://github.com/ilyagr) in [#&#8203;461](jdx/usage#461)

##### 🔍 Other Changes

- add cargo-semver-checks to detect breaking changes by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;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 [@&#8203;jdx](https://github.com/jdx) in [#&#8203;446](jdx/usage#446)
- add logo to docs site by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;442](jdx/usage#442)
- add VT323 retro terminal font and --usage branding by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;443](jdx/usage#443)
- add missing builder methods by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;444](jdx/usage#444)

##### 🐛 Bug Fixes

- use pithy LLM-generated title for GitHub releases by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;441](jdx/usage#441)
- replace unwrap calls with proper error handling in fig.rs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;454](jdx/usage#454)
- improve error messages with more context by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;449](jdx/usage#449)
- skip powershell test if pwsh is not installed by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;457](jdx/usage#457)
- match completion prefix against unescaped names by [@&#8203;ilyagr](https://github.com/ilyagr) in [#&#8203;460](jdx/usage#460)

##### 🚜 Refactor

- simplify Spec::merge with local macros by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;451](jdx/usage#451)

##### 📚 Documentation

- add CLAUDE.md for Claude Code guidance by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;452](jdx/usage#452)
- escape generic type parameters in macro doc comments by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;453](jdx/usage#453)
- add rustdoc for public API functions by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;450](jdx/usage#450)
- add documentation to public API structs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;455](jdx/usage#455)
- add conventional commit guidance to CLAUDE.md by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;459](jdx/usage#459)

##### ⚡ Performance

- remove unnecessary clone in set\_subcommand\_ancestors by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;448](jdx/usage#448)

##### 🧪 Testing

- add test coverage for untested modules by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;447](jdx/usage#447)

##### 🔍 Other Changes

- remove commented-out trait implementations in mount.rs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;445](jdx/usage#445)
- make codecov checks informational by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;456](jdx/usage#456)

##### 📦️ Dependency Updates

- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;439](jdx/usage#439)

##### New Contributors

- [@&#8203;ilyagr](https://github.com/ilyagr) made their first contribution in [#&#8203;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-->
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.

2 participants