-
Notifications
You must be signed in to change notification settings - Fork 26
fix: replace unwrap calls with proper error handling in fig.rs #454
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
- Handle None case in description_format serializer gracefully - Handle empty strings in uppercase conversion - Replace filter + unwrap patterns with filter_map - Return proper miette errors for parse_from_spec and JSON serialization failures This improves robustness and prevents potential panics during Fig spec generation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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 handling in the Fig spec generator by replacing potentially panicking unwrap() calls with proper error handling mechanisms.
Changes:
- Adds safe pattern matching for
Optiontypes in the description formatter - Replaces
filter + unwrappatterns withfilter_mapfor cleaner functional code - Introduces proper
mietteerror handling for command parsing and JSON serialization failures
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if let Some(first_upper) = v[0].to_uppercase().next() { | ||
| v[0] = first_upper; | ||
| } |
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.
Potential index out of bounds panic if the string is empty. The empty string check on line 28-30 should occur before collecting chars into the vector to prevent accessing v[0] when the vector is empty.
| .filter_map(|cmd| cmd.generate_spec.as_ref().map(|spec| (cmd, spec))) | ||
| .for_each(|(_, call_template_str)| { |
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 cmd reference is being cloned in the closure and then immediately discarded (using _). Consider using cmd.generate_spec.as_ref() directly in the closure body instead of creating the tuple, or rename the parameter if cmd is actually needed elsewhere in the closure.
| .filter_map(|cmd| cmd.generate_spec.as_ref().map(|spec| (cmd, spec))) | |
| .for_each(|(_, call_template_str)| { | |
| .filter_map(|cmd| cmd.generate_spec.as_ref()) | |
| .for_each(|call_template_str| { |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #454 +/- ##
==========================================
- Coverage 47.66% 47.29% -0.37%
==========================================
Files 47 47
Lines 6928 6981 +53
Branches 6928 6981 +53
==========================================
Hits 3302 3302
- Misses 1780 1833 +53
Partials 1846 1846 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Replace risky
unwrap()calls in the Fig spec generator with proper error handling to prevent panics.Changes
Noneand empty string cases gracefully instead of panickingfilter + unwrappattern withfilter_mapfor cleaner codemietteerrors for:parse_from_specfailure (command may be hidden)filter + unwrapwithfilter_mapfilter_mapinstead ofmap + filter + unwrapBefore/After
🤖 Generated with Claude Code
Note
Strengthens robustness and cleans up the Fig spec generator.
None/empty descriptions and safely uppercases first charmietteerrors onparse_from_specfailure and JSON serialization failure; builds output unchanged otherwisefilter + unwrapwithfilter_mapinget_generators, mount command handling, andfill_args_completeWritten by Cursor Bugbot for commit b590017. This will update automatically on new commits. Configure here.