Skip to content

Commit

Permalink
Merge pull request #76 from DeterminateSystems/cole/fh-315-m-n-c-bett…
Browse files Browse the repository at this point in the history
…er-tracing

Make source of IO errors more obvious
  • Loading branch information
cole-h authored Jun 6, 2024
2 parents 06ffb16 + 0a64d2c commit f9076a8
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions magic-nix-cache/src/flakehub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,24 @@ pub async fn init_cache(
) -> Result<State> {
// Parse netrc to get the credentials for api.flakehub.com.
let netrc = {
let mut netrc_file = File::open(flakehub_api_server_netrc).await?;
let mut netrc_file = File::open(flakehub_api_server_netrc).await.map_err(|e| {
Error::Internal(format!(
"Failed to open {}: {}",
flakehub_api_server_netrc.display(),
e
))
})?;
let mut netrc_contents = String::new();
netrc_file.read_to_string(&mut netrc_contents).await?;
netrc_file
.read_to_string(&mut netrc_contents)
.await
.map_err(|e| {
Error::Internal(format!(
"Failed to read {} contents: {}",
flakehub_api_server_netrc.display(),
e
))
})?;
netrc_rs::Netrc::parse(netrc_contents, false).map_err(Error::Netrc)?
};

Expand Down Expand Up @@ -84,7 +99,15 @@ pub async fn init_cache(
.create(false)
.append(true)
.open(flakehub_api_server_netrc)
.await?;
.await
.map_err(|e| {
Error::Internal(format!(
"Failed to open {} for appending: {}",
flakehub_api_server_netrc.display(),
e
))
})?;

netrc_file
.write_all(
format!(
Expand All @@ -93,7 +116,14 @@ pub async fn init_cache(
)
.as_bytes(),
)
.await?;
.await
.map_err(|e| {
Error::Internal(format!(
"Failed to write credentials to {}: {}",
flakehub_api_server_netrc.display(),
e
))
})?;
}

let server_config = ServerConfig {
Expand Down

0 comments on commit f9076a8

Please sign in to comment.