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