diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index c22f1957fd..6103af4a1e 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -67,6 +67,8 @@ impl Command for External { } else { return Err(ShellError::ExternalCommand( "Cannot convert argument to a string".into(), + "All arguments to an external command need to be string-compatible" + .into(), val.span()?, )); } @@ -74,6 +76,7 @@ impl Command for External { } else { return Err(ShellError::ExternalCommand( "Cannot convert argument to a string".into(), + "All arguments to an external command need to be string-compatible".into(), arg.span()?, )); } @@ -141,7 +144,8 @@ impl<'call> ExternalCommand<'call> { match process.spawn() { Err(err) => Err(ShellError::ExternalCommand( - format!("{}", err), + "can't run executable".to_string(), + err.to_string(), self.name.span, )), Ok(mut child) => { @@ -186,6 +190,8 @@ impl<'call> ExternalCommand<'call> { let stdout = child.stdout.take().ok_or_else(|| { ShellError::ExternalCommand( "Error taking stdout from external".to_string(), + "Redirects need access to stdout of an external command" + .to_string(), span, ) })?; @@ -220,7 +226,11 @@ impl<'call> ExternalCommand<'call> { } match child.wait() { - Err(err) => Err(ShellError::ExternalCommand(format!("{}", err), span)), + Err(err) => Err(ShellError::ExternalCommand( + "External command exited with error".into(), + err.to_string(), + span, + )), Ok(_) => Ok(()), } }); diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index be7876a39a..af163fa0ae 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -142,8 +142,8 @@ pub enum ShellError { ), #[error("External command")] - #[diagnostic(code(nu::shell::external_command), url(docsrs))] - ExternalCommand(String, #[label("{0}")] Span), + #[diagnostic(code(nu::shell::external_command), url(docsrs), help("{1}"))] + ExternalCommand(String, String, #[label("{0}")] Span), #[error("Unsupported input")] #[diagnostic(code(nu::shell::unsupported_input), url(docsrs))] diff --git a/src/tests.rs b/src/tests.rs index e767ce58a3..a34d6a477c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -75,9 +75,5 @@ pub fn fail_test(input: &str, expected: &str) -> TestResult { #[cfg(test)] pub fn not_found_msg() -> &'static str { - if cfg!(windows) { - "not found" - } else { - "No such" - } + "can't run executable" }