Skip to content

Commit

Permalink
Improving child error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbor committed Jul 8, 2024
1 parent 7ca8016 commit 9d82963
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ pub enum ZinnError {
#[error("{0}")]
Yaml(#[from] serde_yaml::Error),

#[error("Child exited unsuccessfully")]
Child(),
#[error("Child exited with error {0}")]
ChildFailed(i32),

#[error("Child terminated by signal")]
ChildSignaled(),

#[error("Dependency not found ({0})")]
DependencyNotFound(String),
Expand Down
9 changes: 6 additions & 3 deletions src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ impl InnerJobRealization {
}

let (io_reader, io_writer) = os_pipe::pipe()?;

let cmd_with_exit_setting = format!("set -e; {}", self.run);
let mut process = Command::new("sh")
.arg("-c")
.arg(&self.run)
.arg(cmd_with_exit_setting)
.stdout(io_writer.try_clone()?)
.stderr(io_writer)
.spawn()?;
Expand Down Expand Up @@ -252,7 +252,10 @@ impl InnerJobRealization {
}

if !status.success() {
Err(ZinnError::Child())
match status.code() {
Some(code) => Err(ZinnError::ChildFailed(code)),
None => Err(ZinnError::ChildSignaled()),
}
} else {
Ok(JobState::Finished)
}
Expand Down

0 comments on commit 9d82963

Please sign in to comment.