This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Commit 128fdc7
authored
Improve subcommand validation error messages (#62)
* Add recursive validation for subcommand arguments
Previously, when a subcommand was provided but was missing required
arguments, facet deserialization errors would leak through with unhelpful
messages like 'Error: missing field `name` in type `InitArgs`'.
This commit:
- Adds recursive validation in collect_missing_in_arg_level() that checks
subcommand arguments when the subcommand is present
- Adds comprehensive test suite (subcommand_errors.rs) with 10 test cases
covering various missing argument scenarios
- Adds format_missing_cli_args_with_mockup() for user-friendly CLI errors
- Updates driver to use CLI-focused error format when all missing fields
are CLI arguments
Before:
Error: missing field `name` in type `InitArgs`
After:
Error: Missing required arguments
You provided:
init
Missing:
<name> # Project name (creates directory with this name)
Example usage:
init name
This is still a work in progress - needs refinement for edge cases and
consistency across different argument structures.
* Fix clippy collapsible_match warning
* Accept updated snapshots with new error format
* Refactor CLI error formatting for cleaner empty args handling
- Change format_missing_cli_args_with_mockup() to accept Option<&str>
instead of requiring comparison against magic string
- Remove 'You provided:' section when no args given
- Show actual program name in examples instead of '<no arguments>'
- Use placeholder syntax in examples: <name> and --flag <flag-name>
Before:
Error: Error: Missing required arguments
You provided: <no arguments>
Example: <no arguments> --flag <value>
After:
Error: Missing required arguments
Missing: --flag
Example: program --flag <flag>
* Implement Ariadne-based visual error format for missing CLI arguments
- Add MissingFieldKind enum to properly distinguish CLI args from config fields
- Show corrected command with missing argument in Ariadne source
- Highlight the missing argument with green color
- Display field documentation directly in the label
- Only use Ariadne format for actual CLI args (not config fields)
Example output:
Error: missing required argument
╭─[ <unknown>:1:6 ]
│
1 │ init <name>
│ ───┬──
│ ╰──── Project name (creates directory with this name)
───╯
Known issues:
- Duplicate Error: prefix (Ariadne + wrapper)
- Source shows <unknown> instead of <cli>
* Fix duplicate Error prefix and source name by using proper architecture
Instead of pre-formatting Ariadne output as a string, we now:
- Build structured Diagnostics with spans on the corrected command
- Set the corrected command as the source (named '<suggestion>')
- Let DriverReport's render_pretty handle the Ariadne formatting
This eliminates both issues:
- No more 'Error: Error:' duplication
- Source shows '<suggestion>' instead of '<unknown>'
The corrected command becomes THE source for the error, which is
architecturally cleaner and reuses existing infrastructure.
* Fix clippy errors: remove loop that never loops and dead code
* Add label field to Diagnostic for separate label text
Main error message is now generic ('missing required argument')
while the label shows field-specific documentation.
Before:
Error: Project name (creates directory with this name)
...
╰──── Project name (creates directory with this name)
After:
Error: missing required argument
...
╰──── Project name (creates directory with this name)
* Conditionally show help hint only if schema has help field
Now only shows 'Run with --help' if the schema actually defines
a help field (e.g., FigueBuiltins). This prevents suggesting --help
when it's not available.
* Update snapshots
* Include enum variants in help, cf. #60
* Fix one snapshot
* Strip the hexadecimal suffixes that test binaries have so that CI passes reliably.
* Update snapshots1 parent e20a2f8 commit 128fdc7
39 files changed
Lines changed: 1131 additions & 266 deletions
File tree
- crates/figue
- src
- layers
- tests
- common
- integration
- snapshots
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments