Skip to content

🧹 [code health] Refactor tests in src/utils.rs to use ? instead of .unwrap()#158

Merged
ffalcinelli merged 1 commit into
mainfrom
fix-utils-test-unwrap-13147059969945317625
Jul 10, 2026
Merged

🧹 [code health] Refactor tests in src/utils.rs to use ? instead of .unwrap()#158
ffalcinelli merged 1 commit into
mainfrom
fix-utils-test-unwrap-13147059969945317625

Conversation

@ffalcinelli

Copy link
Copy Markdown
Owner

🎯 What: The code health issue addressed was the use of .unwrap() in test functions within src/utils.rs, which can cause runtime panics on errors. We modified these functions to return anyhow::Result<()> and use the ? operator instead.

πŸ’‘ Why: How this improves maintainability: Changing .unwrap() to ? handles errors idiomatically without panicking. While panics in tests are sometimes acceptable, returning a Result is cleaner, avoids abrupt process termination, and aligns better with Rust's robust error-handling paradigms, making the code easier to read and maintain.

βœ… Verification: How you confirmed the change is safe: We successfully ran the full test suite (cargo test) to ensure no existing functionality was broken. The refactoring only applied to the test functions (test_to_sorted_yaml_with_secrets, test_to_sorted_yaml_with_secrets_struct, test_to_sorted_yaml_simple, and test_write_secure_permissions), ensuring no runtime behavior changes to the actual application logic. Code review confirmed safety and completeness.

✨ Result: The improvement achieved: Removed .unwrap() usages from src/utils.rs tests, modernizing them to utilize Rust's Result type and ? operator for safer and cleaner error propagation.


PR created automatically by Jules for task 13147059969945317625 started by @ffalcinelli

Replaced `.unwrap()` calls with `?` in `src/utils.rs` test functions, converting them to return `anyhow::Result<()>`. This handles errors properly without panicking and improves the maintainability of the test codebase.

Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 92.11%. Comparing base (afe490d) to head (490f378).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #158   +/-   ##
=======================================
  Coverage   92.11%   92.11%           
=======================================
  Files          29       29           
  Lines        2358     2358           
=======================================
  Hits         2172     2172           
  Misses        186      186           

β˜” View full report in Codecov by Harness.
πŸ“’ 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.

@ffalcinelli ffalcinelli merged commit 983cd91 into main Jul 10, 2026
10 checks passed
@ffalcinelli ffalcinelli deleted the fix-utils-test-unwrap-13147059969945317625 branch July 10, 2026 14:59
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.

1 participant