Unverified Commit ee9e6887 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Use `format!` instead of `anyhow!` inside of…

Turbopack: Use `format!` instead of `anyhow!` inside of `anyhow::Context::with_context` calls (#88293)

`anyhow!` works here because we just need something that implements `Display`, but `format!` is better.
parent dc5f5b1c
......@@ -5,7 +5,7 @@ use std::{
sync::{Arc, LazyLock, Mutex, PoisonError, Weak},
};
use anyhow::{Context, Result, anyhow};
use anyhow::{Context, Result};
use turbo_bincode::{
TurboBincodeBuffer, turbo_bincode_decode, turbo_bincode_encode, turbo_bincode_encode_into,
};
......@@ -328,7 +328,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
WriteBuffer::Borrowed(&task_id.to_le_bytes()),
)
.with_context(|| {
anyhow!(
format!(
"Unable to write task cache {task_type:?} => {task_id}"
)
})?;
......@@ -339,7 +339,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
WriteBuffer::Borrowed(&task_type_bytes),
)
.with_context(|| {
anyhow!(
format!(
"Unable to write task cache {task_id} => {task_type:?}"
)
})?;
......@@ -373,14 +373,14 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
batch
.put(KeySpace::TaskMeta, WriteBuffer::Borrowed(key), meta)
.with_context(|| {
anyhow!("Unable to write meta items for {task_id}")
format!("Unable to write meta items for {task_id}")
})?;
}
if let Some(data) = data {
batch
.put(KeySpace::TaskData, WriteBuffer::Borrowed(key), data)
.with_context(|| {
anyhow!("Unable to write data items for {task_id}")
format!("Unable to write data items for {task_id}")
})?;
}
}
......@@ -415,7 +415,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
WriteBuffer::Borrowed(&task_id.to_le_bytes()),
)
.with_context(|| {
anyhow!("Unable to write task cache {task_type:?} => {task_id}")
format!("Unable to write task cache {task_type:?} => {task_id}")
})?;
batch
.put(
......@@ -424,7 +424,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
WriteBuffer::Borrowed(&task_type_bytes),
)
.with_context(|| {
anyhow!("Unable to write task cache {task_id} => {task_type:?}")
format!("Unable to write task cache {task_id} => {task_type:?}")
})?;
next_task_id = next_task_id.max(task_id + 1);
}
......@@ -440,9 +440,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
{
let _span = tracing::trace_span!("commit").entered();
batch
.commit()
.with_context(|| anyhow!("Unable to commit operations"))?;
batch.commit().context("Unable to commit operations")?;
}
Ok(())
}
......
......@@ -1049,7 +1049,7 @@ impl FileSystem for DiskFileSystem {
Err(err)
}
})
.with_context(|| anyhow!("removing {} failed", full_path.display()))?;
.with_context(|| format!("removing {} failed", full_path.display()))?;
}
}
......@@ -1202,7 +1202,7 @@ impl FileSystem for DiskFileSystem {
.concurrency_limited(&inner.write_semaphore)
.await
.with_context(|| {
anyhow!("removing existing symlink {} failed", full_path.display())
format!("removing existing symlink {} failed", full_path.display())
})?;
}
......@@ -1257,7 +1257,7 @@ impl FileSystem for DiskFileSystem {
))
.concurrency_limited(&inner.write_semaphore)
.await
.with_context(|| anyhow!("removing {} failed", full_path.display()))?;
.with_context(|| format!("removing {} failed", full_path.display()))?;
}
}
......
use std::{error::Error, str::FromStr};
use anyhow::{Context, Result, anyhow};
use anyhow::{Context, Result};
/// Reads an environment variable.
pub fn read_env<T>(name: &str, default: T) -> Result<T>
......@@ -13,7 +13,7 @@ where
None | Some("") => Ok(default),
Some(config) => config
.parse()
.with_context(|| anyhow!("Invalid value for {}", name)),
.with_context(|| format!("Invalid value for {}", name)),
}
}
......@@ -40,7 +40,7 @@ where
.split(',')
.map(|s| {
s.parse()
.with_context(|| anyhow!("Invalid value for {}", name))
.with_context(|| format!("Invalid value for {}", name))
})
.collect(),
}
......
......@@ -16,7 +16,7 @@ use std::{
time::{Duration, Instant},
};
use anyhow::{Context, Result, anyhow};
use anyhow::{Context, Result};
use difference::Changeset;
use helpers::print_changeset;
use regex::Regex;
......@@ -645,8 +645,8 @@ async fn exec_node(directory: &str, path: &str) -> Result<CommandOutput> {
let output = timeout(Duration::from_secs(100), cmd.output())
.await
.with_context(|| anyhow!("node execution of {path} is hanging"))?
.with_context(|| anyhow!("failed to spawn node process of {path}"))?;
.with_context(|| format!("node execution of {path} is hanging"))?
.with_context(|| format!("failed to spawn node process of {path}"))?;
let output = CommandOutput {
stdout: String::from_utf8_lossy(&output.stdout).to_string(),
......
......@@ -8,7 +8,7 @@ use std::{
time::{Duration, UNIX_EPOCH},
};
use anyhow::{Context, anyhow};
use anyhow::Context;
use chrono::{DateTime, Utc};
use indexmap::IndexSet;
use rustc_hash::{FxHashMap, FxHasher};
......@@ -84,7 +84,7 @@ pub fn process_all(path: PathBuf) {
let file = File::open(&data_file.path).unwrap();
let reader = std::io::BufReader::new(file);
let data: BaseBenchmarks = serde_json::from_reader(reader)
.with_context(|| anyhow!("unable to read {}", data_file.path.display()))
.with_context(|| format!("unable to read {}", data_file.path.display()))
.unwrap();
data
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment