Skip to content

Commit

Permalink
more context, less with_context
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Feb 1, 2024
1 parent 3ff7174 commit 021e08f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use std::convert::TryInto;
use std::fs::{File, OpenOptions};
use tar::Builder;

/// These interfaces are similar to some methods in [tar::Builder].
///
/// They use [tokio::block_in_place] to avoid blocking other async
/// tasks using the executor.
#[async_trait]
pub trait AsyncAppendFile {
async fn append_file_async<P>(&mut self, path: P, file: &mut File) -> std::io::Result<()>
Expand Down Expand Up @@ -89,9 +93,7 @@ impl<E: Encoder> ArchiveBuilder<E> {
}

pub fn into_inner(self) -> Result<E> {
self.builder
.into_inner()
.with_context(|| "Finalizing archive")
self.builder.into_inner().context("Finalizing archive")
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl<D: FileDigester> ArtifactManifest<D> {
if extension != "json" {
bail!("JSON encoding is all we know. Write to a '.json' file?");
}
let serialized = serde_json::to_string(&self)
.with_context(|| "Failed to serialize ArtifactManifest to JSON")?;
let serialized =
serde_json::to_string(&self).context("Failed to serialize ArtifactManifest to JSON")?;

let mut f = File::create(path).await?;
f.write_all(serialized.as_bytes()).await?;
Expand Down
12 changes: 6 additions & 6 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ impl Package {
let zoned = true;
let inputs = self
.get_all_inputs(name, target, output_directory, zoned, None)
.with_context(|| "Identifying all input paths")?;
.context("Identifying all input paths")?;
progress.increment_total(inputs.0.len() as u64);

let output_file = self.get_output_file(name);
Expand All @@ -657,7 +657,7 @@ impl Package {
progress.set_message("Cache miss".into());
}
Err(CacheError::Other(other)) => {
return Err(other).with_context(|| "Reading from package cache");
return Err(other).context("Reading from package cache");
}
}

Expand All @@ -680,7 +680,7 @@ impl Package {
cache
.update(&inputs, &output_path)
.await
.with_context(|| "Updating package cache")?;
.context("Updating package cache")?;

timer.finish()?;
Ok(file)
Expand Down Expand Up @@ -779,7 +779,7 @@ impl Package {
let zoned = false;
let inputs = self
.get_all_inputs(name, config.target, output_directory, zoned, None)
.with_context(|| "Identifying all input paths")?;
.context("Identifying all input paths")?;
progress.increment_total(inputs.0.len() as u64);

match cache.lookup(&inputs, &output_path).await {
Expand All @@ -791,7 +791,7 @@ impl Package {
progress.set_message("Cache miss".into());
}
Err(CacheError::Other(other)) => {
return Err(other).with_context(|| "Reading from package cache");
return Err(other).context("Reading from package cache");
}
}

Expand All @@ -814,7 +814,7 @@ impl Package {
cache
.update(&inputs, &output_path)
.await
.with_context(|| "Updating package cache")?;
.context("Updating package cache")?;

Ok(file)
}
Expand Down
2 changes: 1 addition & 1 deletion src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

//! Describes utilities for relaying progress to end-users.
use std::sync::OnceLock;
use slog::Logger;
use std::borrow::Cow;
use std::sync::OnceLock;

/// Trait for propagating progress information while constructing the package.
pub trait Progress {
Expand Down

0 comments on commit 021e08f

Please sign in to comment.