Skip to content

Commit

Permalink
Ensure an output_path is always present
Browse files Browse the repository at this point in the history
Skip cases where this is not the case, as the original nixtract does
  • Loading branch information
Erin van der Veen committed Feb 15, 2024
1 parent 6b4dccb commit 7cb816b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub type Result<T> = std::result::Result<T, Error>;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Could not parse the Nix CLI output: {0}")]
SerdeJSON(#[from] serde_json::Error),
#[error("Could not parse the Nix CLI output for attribute path: {0}: {1}")]
SerdeJSON(String, serde_json::Error),

#[error("Nix exited with a non-zero exit code: {0:#?}: {1}")]
NixCommand(Option<i32>, String),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn nixtract(
tx.clone(),
) {
Ok(_) => {}
Err(e) => log::error!("Error processing derivation: {}", e),
Err(e) => log::warn!("Error processing derivation: {}", e),
}
});
});
Expand Down
5 changes: 4 additions & 1 deletion src/nix/describe_derivation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ pub fn describe_derivation(
}

// Parse the stdout as JSON
let description: DerivationDescription = serde_json::from_str(stdout.trim())?;
let description: DerivationDescription = match serde_json::from_str(stdout.trim()) {
Ok(description) => description,
Err(e) => return Err(Error::SerdeJSON(attribute_path.to_owned(), e)),
};

Ok(description)
}
10 changes: 9 additions & 1 deletion src/nix/find_attribute_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ pub fn find_attribute_paths(
return Err(Error::NixCommand(output.status.code(), stderr.to_string()));
} else {
let attribute_paths: AttributePaths =
serde_json::from_str(line.trim_start_matches("trace: "))?;
match serde_json::from_str(line.trim_start_matches("trace: ")) {
Ok(attribute_paths) => attribute_paths,
Err(e) => {
return Err(Error::SerdeJSON(
attribute_path.clone().unwrap_or_default(),
e,
))
}
};
res.push(attribute_paths);
}
}
Expand Down

0 comments on commit 7cb816b

Please sign in to comment.