Check exit status in ChildProcess::wait

This commit is contained in:
Ian Manske 2024-08-01 20:57:17 -07:00
parent 785aa880b1
commit 854ca25004
4 changed files with 14 additions and 34 deletions

View File

@ -147,7 +147,7 @@ impl Command for Do {
None
};
child.wait()?.check_ok(span)?;
child.wait()?;
let mut child = ChildProcess::from_raw(None, None, None, span);
if let Some(stdout) = stdout {

View File

@ -917,21 +917,6 @@ pub enum ShellError {
span: Span,
},
#[cfg(unix)]
/// An I/O operation failed.
///
/// ## Resolution
///
/// This is a generic error. Refer to the specific error message for further details.
#[error("program coredump error")]
#[diagnostic(code(nu::shell::coredump_error))]
CoredumpErrorSpanned {
msg: String,
signal: i32,
#[label("{msg}")]
span: Span,
},
/// Tried to `cd` to a path that isn't a directory.
///
/// ## Resolution

View File

@ -558,7 +558,7 @@ impl ByteStream {
Ok(())
}
ByteStreamSource::File(_) => Ok(()),
ByteStreamSource::Child(child) => child.wait()?.check_ok(self.span),
ByteStreamSource::Child(child) => child.wait(),
}
}
@ -604,7 +604,7 @@ impl ByteStream {
}
}
}
child.wait()?.check_ok(span)?;
child.wait()?;
}
}
Ok(())
@ -677,7 +677,7 @@ impl ByteStream {
}
(None, None) => {}
}
child.wait()?.check_ok(span)?;
child.wait()?;
}
}

View File

@ -23,21 +23,16 @@ impl ExitStatusFuture {
ExitStatusFuture::Finished(Err(err)) => Err(err.as_ref().clone()),
ExitStatusFuture::Running(receiver) => {
let code = match receiver.recv() {
Ok(Ok(status)) => {
#[cfg(unix)]
if let ExitStatus::Signaled {
signal,
core_dumped: true,
} = status
{
return Err(ShellError::CoredumpErrorSpanned {
msg: format!("coredump detected. received signal: {signal}"),
signal,
span,
});
}
#[cfg(unix)]
Ok(Ok(
status @ ExitStatus::Signaled {
core_dumped: true, ..
},
)) => {
status.check_ok(span)?;
Ok(status)
}
Ok(Ok(status)) => Ok(status),
Ok(Err(err)) => Err(ShellError::IOErrorSpanned {
msg: format!("failed to get exit code: {err:?}"),
span,
@ -192,7 +187,7 @@ impl ChildProcess {
Ok(bytes)
}
pub fn wait(mut self) -> Result<ExitStatus, ShellError> {
pub fn wait(mut self) -> Result<(), ShellError> {
if let Some(stdout) = self.stdout.take() {
let stderr = self
.stderr
@ -228,7 +223,7 @@ impl ChildProcess {
consume_pipe(stderr).err_span(self.span)?;
}
self.exit_status.wait(self.span)
self.exit_status.wait(self.span)?.check_ok(self.span)
}
pub fn try_wait(&mut self) -> Result<Option<ExitStatus>, ShellError> {