Skip to content

Commit

Permalink
Make cache-write failures non-fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 12, 2024
1 parent 17e84d5 commit 4b8a7d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions crates/ruff/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,22 @@ impl Cache {
.write_all(&serialized)
.context("Failed to write serialized cache to temporary file.")?;

temp_file.persist(&self.path).with_context(|| {
format!(
"Failed to rename temporary cache file to {}",
self.path.display()
)
})?;
if let Err(err) = temp_file.persist(&self.path) {
if err.error.kind() == io::ErrorKind::PermissionDenied {
warn_user!(
"Failed to write cache file '{}': {}",
self.path.display(),
err.error
);
} else {
return Err(err).with_context(|| {
format!(
"Failed to rename temporary cache file to {}",
self.path.display()
)
});
}
}

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions crates/ruff/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub(crate) fn format(
duration
);

// Store the caches.
caches.persist()?;

// Report on any errors.
Expand Down

0 comments on commit 4b8a7d2

Please sign in to comment.