Skip to content

Commit

Permalink
address string interpolation outside of proper context
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
gumpt authored and eaufavor committed Apr 22, 2024
1 parent a23d4d8 commit a8b6bbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5fa74f2bf1f95b283bbeb819687777d5592218ee
a92e9ba819522dbe0750e9cd9be49d8b813a4e69
22 changes: 13 additions & 9 deletions pingora-cache/src/eviction/simple_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?
Expand All @@ -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}")?;
Expand Down
6 changes: 4 additions & 2 deletions pingora-core/src/listeners/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ impl TlsSettings {
)?;
accept_builder
.set_private_key_file(key_path, SslFiletype::PEM)
.or_err(TLS_CONF_ERR, "fail to read key file {key_path}")?;
.or_err_with(TLS_CONF_ERR, || format!("fail to read key file {key_path}"))?;
accept_builder
.set_certificate_chain_file(cert_path)
.or_err(TLS_CONF_ERR, "fail to read cert file {cert_path}")?;
.or_err_with(TLS_CONF_ERR, || {
format!("fail to read cert file {cert_path}")
})?;
Ok(TlsSettings {
accept_builder,
callbacks: None,
Expand Down

0 comments on commit a8b6bbe

Please sign in to comment.