From a246a19387594cea15618a89a4bcd9d4c439d16a Mon Sep 17 00:00:00 2001 From: Access Date: Fri, 7 Jun 2024 21:02:52 +0800 Subject: [PATCH] fix: coredump without any messages (#13034) # Description - this PR should close https://github.com/nushell/nushell/issues/12874 - fixes https://github.com/nushell/nushell/issues/12874 I want to fix the issue which is induced by the fix for https://github.com/nushell/nushell/issues/12369. after this pr. This pr induced a new error for unix system, in order to show coredump messages # User-Facing Changes after fix for 12874, coredump message is messing, so I want to fix it # Tests + Formatting # After Submitting ![image](https://github.com/nushell/nushell/assets/60290287/6d8ab756-3031-4212-a5f5-5f71be3857f9) --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> --- crates/nu-protocol/src/errors/shell_error.rs | 15 +++++++++++++++ crates/nu-protocol/src/process/child.rs | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/nu-protocol/src/errors/shell_error.rs b/crates/nu-protocol/src/errors/shell_error.rs index a8ca52142c..e201915fcf 100644 --- a/crates/nu-protocol/src/errors/shell_error.rs +++ b/crates/nu-protocol/src/errors/shell_error.rs @@ -876,6 +876,21 @@ 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/process/child.rs b/crates/nu-protocol/src/process/child.rs index cc74b40fc1..08da7e704c 100644 --- a/crates/nu-protocol/src/process/child.rs +++ b/crates/nu-protocol/src/process/child.rs @@ -23,7 +23,21 @@ impl ExitStatusFuture { ExitStatusFuture::Finished(Err(err)) => Err(err.as_ref().clone()), ExitStatusFuture::Running(receiver) => { let code = match receiver.recv() { - Ok(Ok(status)) => Ok(status), + 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, + }); + } + Ok(status) + } Ok(Err(err)) => Err(ShellError::IOErrorSpanned { msg: format!("failed to get exit code: {err:?}"), span,