diff options
author | Matthew Gumport <[email protected]> | 2024-04-05 16:37:35 -0700 |
---|---|---|
committer | Yuchen Wu <[email protected]> | 2024-04-22 08:48:19 -0700 |
commit | a8b6bbe9f42eee6d1c771a4d38080d6a98626792 (patch) | |
tree | 1abccc852f769d80f8f45b7edad169330a73ebee /pingora-cache | |
parent | a23d4d8ef1602d4042c223bc8e33067e57fb7746 (diff) | |
download | pingora-a8b6bbe9f42eee6d1c771a4d38080d6a98626792.tar.gz pingora-a8b6bbe9f42eee6d1c771a4d38080d6a98626792.zip |
address string interpolation outside of proper context
https://github.com/cloudflare/pingora/issues/181
Ran:
```
rg --pcre2 '(?<!(trace\!\()|(println\!\()|(warn\!\()|(info\!\()|(debug\!\()|(format\!\()|(error\!\()|(write\!\()|(panic\!\())\".*\{.+\"'
```
and audited the 200+ results by hand. Only messed up in a few places!
Hat-tip to Kevin for helping me understand the compile error messages I was
seeing trying to fix this naively.
Diffstat (limited to 'pingora-cache')
-rw-r--r-- | pingora-cache/src/eviction/simple_lru.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/pingora-cache/src/eviction/simple_lru.rs b/pingora-cache/src/eviction/simple_lru.rs index 43009a8..caa9293 100644 --- a/pingora-cache/src/eviction/simple_lru.rs +++ b/pingora-cache/src/eviction/simple_lru.rs @@ -222,15 +222,18 @@ impl EvictionManager for Manager { async fn save(&self, dir_path: &str) -> Result<()> { let data = self.serialize()?; - let dir_path = dir_path.to_owned(); + let dir_str = dir_path.to_owned(); tokio::task::spawn_blocking(move || { - let dir_path = Path::new(&dir_path); - std::fs::create_dir_all(dir_path).or_err(InternalError, "fail to create {dir_path}")?; + let dir_path = Path::new(&dir_str); + std::fs::create_dir_all(dir_path) + .or_err_with(InternalError, || format!("fail to create {dir_str}"))?; let file_path = dir_path.join(FILE_NAME); - let mut file = - File::create(file_path).or_err(InternalError, "fail to create {file_path}")?; - file.write_all(&data) - .or_err(InternalError, "fail to write to {file_path}") + let mut file = File::create(&file_path).or_err_with(InternalError, || { + format!("fail to create {}", file_path.display()) + })?; + file.write_all(&data).or_err_with(InternalError, || { + format!("fail to write to {}", file_path.display()) + }) }) .await .or_err(InternalError, "async blocking IO failure")? @@ -240,8 +243,9 @@ impl EvictionManager for Manager { let dir_path = dir_path.to_owned(); let data = tokio::task::spawn_blocking(move || { let file_path = Path::new(&dir_path).join(FILE_NAME); - let mut file = - File::open(file_path).or_err(InternalError, "fail to open {file_path}")?; + let mut file = File::open(file_path.clone()).or_err_with(InternalError, || { + format!("fail to open {}", file_path.display()) + })?; let mut buffer = Vec::with_capacity(8192); file.read_to_end(&mut buffer) .or_err(InternalError, "fail to write to {file_path}")?; |