From 854ca2500417b41c90ea300626c8b62721d0daf4 Mon Sep 17 00:00:00 2001 From: Ian Manske Date: Thu, 1 Aug 2024 20:57:17 -0700 Subject: [PATCH] Check exit status in `ChildProcess::wait` --- crates/nu-cmd-lang/src/core_commands/do_.rs | 2 +- crates/nu-protocol/src/errors/shell_error.rs | 15 ----------- .../nu-protocol/src/pipeline/byte_stream.rs | 6 ++--- crates/nu-protocol/src/process/child.rs | 25 ++++++++----------- 4 files changed, 14 insertions(+), 34 deletions(-) diff --git a/crates/nu-cmd-lang/src/core_commands/do_.rs b/crates/nu-cmd-lang/src/core_commands/do_.rs index 0f83d5e456..f286c50644 100644 --- a/crates/nu-cmd-lang/src/core_commands/do_.rs +++ b/crates/nu-cmd-lang/src/core_commands/do_.rs @@ -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 { diff --git a/crates/nu-protocol/src/errors/shell_error.rs b/crates/nu-protocol/src/errors/shell_error.rs index da9aed6904..e9e57bc05f 100644 --- a/crates/nu-protocol/src/errors/shell_error.rs +++ b/crates/nu-protocol/src/errors/shell_error.rs @@ -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 diff --git a/crates/nu-protocol/src/pipeline/byte_stream.rs b/crates/nu-protocol/src/pipeline/byte_stream.rs index 2ff9c286bc..e2329784b8 100644 --- a/crates/nu-protocol/src/pipeline/byte_stream.rs +++ b/crates/nu-protocol/src/pipeline/byte_stream.rs @@ -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()?; } } diff --git a/crates/nu-protocol/src/process/child.rs b/crates/nu-protocol/src/process/child.rs index 3f287c08cf..320427a819 100644 --- a/crates/nu-protocol/src/process/child.rs +++ b/crates/nu-protocol/src/process/child.rs @@ -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 { + 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, ShellError> {