🧹 Replace unwrap() with safe fallback in TtlLruCache - #8
Conversation
Replaced `unwrap()` calls when initializing `NonZeroUsize` for the `LruCache` capacity. Used `unwrap_or(NonZeroUsize::MIN)` to provide a safe fallback of 1 instead of panicking, improving the robustness and maintainability of the search cache. - Modified `TtlLruCache::new()` - Modified `TtlLruCache::with_config()` Verified with a standalone Rust script since `cargo test` was unavailable due to network constraints. Co-authored-by: LeandroPG19 <151863062+LeandroPG19@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR addresses a code health issue in the Rust search cache by removing unsafe
unwrap()calls when creating aNonZeroUsizefor cache capacity. These have been replaced withunwrap_or(NonZeroUsize::MIN), which ensures the cache always has a minimum size of 1 even if the configuration is invalid, preventing potential panics.Changes:
TtlLruCache::new(), replaced.unwrap()with.unwrap_or(NonZeroUsize::MIN).TtlLruCache::with_config(), replaced the.max(1).unwrap()pattern with.unwrap_or(NonZeroUsize::MIN).Verification:
The changes were verified using a standalone Rust script that confirmed identical behavior between the old and new logic for both zero and non-zero inputs, while providing greater safety. Existing tests in the codebase cover the cache functionality and were reviewed for compatibility.
PR created automatically by Jules for task 10090660793338763548 started by @LeandroPG19