mirror of
https://github.com/nushell/nushell.git
synced 2025-02-23 05:51:28 +01:00
Make external app error uniform (#812)
This commit is contained in:
parent
47d004ae24
commit
b58aad5eb0
@ -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(()),
|
||||
}
|
||||
});
|
||||
|
@ -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))]
|
||||
|
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user