mirror of
https://github.com/nushell/nushell.git
synced 2024-11-29 11:54:02 +01:00
Return error when kill
didn't terminate successfully (#6354)
* Return error when `kill` didn't terminate successfully Signed-off-by: nibon7 <nibon7@163.com> * add test Signed-off-by: nibon7 <nibon7@163.com> Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
parent
2b955f82b7
commit
529c98085a
@ -132,10 +132,37 @@ impl Command for Kill {
|
||||
.stderr(Stdio::null());
|
||||
}
|
||||
|
||||
let output = cmd.output().expect("failed to execute shell command");
|
||||
let output = cmd.output().map_err(|e| {
|
||||
ShellError::GenericError(
|
||||
"failed to execute shell command".into(),
|
||||
e.to_string(),
|
||||
Some(call.head),
|
||||
None,
|
||||
Vec::new(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if !quiet && !output.status.success() {
|
||||
return Err(ShellError::GenericError(
|
||||
"process didn't terminate successfully".into(),
|
||||
String::from_utf8(output.stderr).unwrap_or_default(),
|
||||
Some(call.head),
|
||||
None,
|
||||
Vec::new(),
|
||||
));
|
||||
}
|
||||
|
||||
let val = String::from(
|
||||
String::from_utf8(output.stdout)
|
||||
.expect("failed to convert output to string")
|
||||
.map_err(|e| {
|
||||
ShellError::GenericError(
|
||||
"failed to convert output to string".into(),
|
||||
e.to_string(),
|
||||
Some(call.head),
|
||||
None,
|
||||
Vec::new(),
|
||||
)
|
||||
})?
|
||||
.trim_end(),
|
||||
);
|
||||
if val.is_empty() {
|
||||
|
@ -48,6 +48,7 @@ mod open;
|
||||
mod p;
|
||||
mod parse;
|
||||
mod path;
|
||||
mod platform;
|
||||
mod prepend;
|
||||
mod print;
|
||||
#[cfg(feature = "database")]
|
||||
|
9
crates/nu-command/tests/commands/platform/kill.rs
Normal file
9
crates/nu-command/tests/commands/platform/kill.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[test]
|
||||
fn test_kill_invalid_pid() {
|
||||
let pid = i32::MAX;
|
||||
let actual = nu!(format!("kill {}", pid));
|
||||
|
||||
assert!(actual.err.contains("process didn't terminate successfully"));
|
||||
}
|
1
crates/nu-command/tests/commands/platform/mod.rs
Normal file
1
crates/nu-command/tests/commands/platform/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
mod kill;
|
Loading…
Reference in New Issue
Block a user