Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cache-write failures non-fatal #12302

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions crates/ruff/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,24 @@ 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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The open method on this struct already uses a similar pattern of warning (but ignoring) some errors.

// On Windows, writing to the cache file can fail if the file is still open (e.g., if
// the user is running Ruff from multiple processes over the same directory).
if cfg!(windows) && 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
Loading