Skip to content

Commit

Permalink
Avoid .unwrap() on cache access (#5229)
Browse files Browse the repository at this point in the history
## Summary

I haven't been able to determine why / when this is happening, but in
some cases, users are reporting that this `unwrap()` is causing a panic.
It's fine to just return `None` here and fallback to "No cache",
certainly better than panicking (while we figure out the edge case).

Closes #5225.

Closes #5228.
  • Loading branch information
charliermarsh authored Jun 20, 2023
1 parent 4717d07 commit 1a2bd98
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions crates/ruff_cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ pub(crate) fn run(

let settings = resolver.resolve_all(path, pyproject_config);
let package_root = package.unwrap_or_else(|| path.parent().unwrap_or(path));
let cache = caches
.as_ref()
.map(|caches| caches.get(&package_root).unwrap());
let cache = caches.as_ref().and_then(|caches| caches.get(&package_root));

lint_path(path, package, settings, cache, noqa, autofix).map_err(|e| {
(Some(path.to_owned()), {
Expand Down

0 comments on commit 1a2bd98

Please sign in to comment.