Skip to content

Commit

Permalink
Check if nixtract produced any output
Browse files Browse the repository at this point in the history
This avoids a problem where `genealogos` would produce an empty sbom.

We check for both the status code and the output. The latter should not be needed, but `nixtract` does not yet produce non-zero status codes.
  • Loading branch information
Erin van der Veen committed Jan 22, 2024
1 parent af4ee3f commit fc0d617
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions genealogos/src/backend/nixtract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ impl crate::backend::BackendTrait for Nixtract {
let output = command.output()?;
let stdout = String::from_utf8_lossy(&output.stdout);

// Check if the command was successful
if !output.status.success() {
return Err(crate::Error::NixtractCommand(format!(
"nixtract exited with status code {}",
output.status
)));
} else if output.stdout.is_empty() {
return Err(crate::Error::NixtractCommand(
"nixtract produced no output".to_string(),
));
}

// Split stdout into lines
let lines = stdout.lines();

Expand Down
2 changes: 1 addition & 1 deletion genealogos/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum Error {
#[error("Errors constructing CycloneDX output: {0}")]
CycloneDX(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),

#[error("Nixtract exited with a non-zero exit code: {0}")]
#[error("Nixtract failed: {0}")]
NixtractCommand(String),

#[error("Genealogos encountered an IO error: {0}")]
Expand Down

0 comments on commit fc0d617

Please sign in to comment.