Skip to content

Commit

Permalink
convert unwraps to expects
Browse files Browse the repository at this point in the history
  • Loading branch information
colemickens committed Aug 29, 2024
1 parent 21a9552 commit fa02e9a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
9 changes: 7 additions & 2 deletions gha-cache/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ impl Api {
let url = self.construct_url(&format!("caches/{}", allocation.0 .0));

tokio::task::spawn(async move {
let permit = concurrency_limit.acquire().await.unwrap();
let permit = concurrency_limit
.acquire()
.await
.expect("failed to acquire concurrency semaphore permit");

tracing::trace!(
"Starting uploading chunk {}-{}",
Expand Down Expand Up @@ -411,7 +414,9 @@ impl Api {
future::join_all(futures)
.await
.into_iter()
.try_for_each(|join_result| join_result.unwrap())?;
.try_for_each(|join_result| {
join_result.expect("failed collecting a join result during parallel upload")
})?;

tracing::debug!("Received all chunks for cache {:?}", allocation.0);

Expand Down
18 changes: 15 additions & 3 deletions magic-nix-cache/src/gha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ impl GhaCache {
self.channel_tx
.send(Request::Shutdown)
.expect("Cannot send shutdown message");
worker_result.await.unwrap()
worker_result
.await
.expect("failed to read result from gha worker")
} else {
Ok(())
}
Expand Down Expand Up @@ -189,7 +191,7 @@ async fn upload_path(

let narinfo = path_info_to_nar_info(store.clone(), &path_info, format!("nar/{}", nar_path))
.to_string()
.unwrap();
.expect("failed to convert path into to nar info");

tracing::debug!("Uploading '{}'", narinfo_path);

Expand Down Expand Up @@ -224,7 +226,17 @@ fn path_info_to_nar_info(store: Arc<NixStore>, path_info: &ValidPathInfo, url: S
references: path_info
.references
.iter()
.map(|r| r.file_name().unwrap().to_str().unwrap().to_owned())
.map(|r| {
r.file_name()
.and_then(|n| n.to_str())
.unwrap_or_else(|| {
panic!(
"failed to convert nar_info reference to string: {}",
r.display()
)
})
.to_owned()
})
.collect(),
system: None,
deriver: None,
Expand Down
12 changes: 10 additions & 2 deletions magic-nix-cache/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,16 @@ fn init_logging() -> Result<LogGuard> {
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
#[cfg(debug_assertions)]
return EnvFilter::new("info")
.add_directive("magic_nix_cache=debug".parse().unwrap())
.add_directive("gha_cache=debug".parse().unwrap());
.add_directive(
"magic_nix_cache=debug"
.parse()
.expect("failed to parse magix_nix_cache directive"),
)
.add_directive(
"gha_cache=debug"
.parse()
.expect("failed to parse gha_cahce directive"),
);

#[cfg(not(debug_assertions))]
return EnvFilter::new("info");
Expand Down

0 comments on commit fa02e9a

Please sign in to comment.