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 None
}; };
child.wait()?.check_ok(span)?; child.wait()?;
let mut child = ChildProcess::from_raw(None, None, None, span); let mut child = ChildProcess::from_raw(None, None, None, span);
if let Some(stdout) = stdout { if let Some(stdout) = stdout {

View File

@ -917,21 +917,6 @@ pub enum ShellError {
span: Span, 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. /// Tried to `cd` to a path that isn't a directory.
/// ///
/// ## Resolution /// ## Resolution

View File

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