Skip to content

fix: replace panicking expect() with map_or() for file_name() check#2688

Open
srpatcha wants to merge 1 commit intomozilla:mainfrom
srpatcha:fix/lru-expect-panic
Open

fix: replace panicking expect() with map_or() for file_name() check#2688
srpatcha wants to merge 1 commit intomozilla:mainfrom
srpatcha:fix/lru-expect-panic

Conversation

@srpatcha
Copy link
Copy Markdown

Summary

\Path::file_name()\ returns \None\ for paths ending in ..\ which caused a panic via .expect(). Replace with .map_or()\ to handle unusual paths gracefully.

This is split from #2679 per reviewer feedback to keep changes focused.

Changes

  • \src/lru_disk_cache/mod.rs: Replace .expect()\ with .map_or(false, ...)\ in the file_name check

Signed-off-by: Srikanth Patchava spatchava@meta.com

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.33%. Comparing base (d11e2e0) to head (7cb0568).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2688      +/-   ##
==========================================
+ Coverage   74.17%   74.33%   +0.16%     
==========================================
  Files          70       70              
  Lines       39207    39372     +165     
==========================================
+ Hits        29083    29269     +186     
+ Misses      10124    10103      -21     

☔ 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.

Path::file_name() returns None for paths ending in '..' which caused
a panic. Build cache tools should handle unusual paths gracefully.

Signed-off-by: Srikanth Patchava <spatchava@meta.com>
Signed-off-by: Srikanth Patchava <srpatcha@users.noreply.github.com>
@srpatcha srpatcha force-pushed the fix/lru-expect-panic branch from 69af502 to 7cb0568 Compare May 6, 2026 04:55
@srpatcha
Copy link
Copy Markdown
Author

srpatcha commented May 6, 2026

Hi, fixed the clippy unnecessary_map_or lint by switching to is_some_and:

\\diff

  • .map_or(false, |name| name.starts_with(TEMPFILE_PREFIX))
  • .is_some_and(|name| name.starts_with(TEMPFILE_PREFIX))
    \\

This is the canonical idiom and matches what clippy stable suggests. Force-pushed; CI should pass on ubuntu, macOS, and windows now.

@sylvestre
Copy link
Copy Markdown
Collaborator

could you please add a test to make sure we don't regress in the future? thanks

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.

3 participants