Skip to content

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jan 19, 2026

Summary

Replace risky unwrap() calls in the Fig spec generator with proper error handling to prevent panics.

Changes

  • description_format serializer: Handle None and empty string cases gracefully instead of panicking
  • get_generators: Replace filter + unwrap pattern with filter_map for cleaner code
  • run(): Return proper miette errors for:
    • parse_from_spec failure (command may be hidden)
    • JSON serialization failure
  • Handle mount commands: Replace filter + unwrap with filter_map
  • fill_args_complete: Simplify with filter_map instead of map + filter + unwrap

Before/After

// Before (could panic)
let s: &str = description.as_ref().unwrap();
v[0] = v[0].to_uppercase().next().unwrap();

// After (handles edge cases)
let s: &str = match description.as_ref() {
    Some(s) => s,
    None => return serializer.serialize_str(""),
};
if let Some(first_upper) = v[0].to_uppercase().next() {
    v[0] = first_upper;
}

🤖 Generated with Claude Code


Note

Strengthens robustness and cleans up the Fig spec generator.

  • description_format serializer: Gracefully handles None/empty descriptions and safely uppercases first char
  • Fig::run(): Returns miette errors on parse_from_spec failure and JSON serialization failure; builds output unchanged otherwise
  • Iterator refactors: Replace filter + unwrap with filter_map in get_generators, mount command handling, and fill_args_complete
  • Minor: avoid panics when accessing first char; simplify option generator extraction

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

- 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>
Copilot AI review requested due to automatic review settings January 19, 2026 19:39
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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 handling in the Fig spec generator by replacing potentially panicking unwrap() calls with proper error handling mechanisms.

Changes:

  • Adds safe pattern matching for Option types in the description formatter
  • Replaces filter + unwrap patterns with filter_map for cleaner functional code
  • Introduces proper miette error handling for command parsing and JSON serialization failures

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +34
if let Some(first_upper) = v[0].to_uppercase().next() {
v[0] = first_upper;
}
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.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +386 to +387
.filter_map(|cmd| cmd.generate_spec.as_ref().map(|spec| (cmd, spec)))
.for_each(|(_, call_template_str)| {
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 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.

Suggested change
.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| {

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

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.29%. Comparing base (949e3a5) to head (b590017).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/cli/generate/fig.rs 0.00% 21 Missing ⚠️
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.
📢 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.

@jdx jdx merged commit cfc30a4 into main Jan 19, 2026
7 of 9 checks passed
@jdx jdx deleted the feat/fig-error-handling branch January 19, 2026 19:46
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