mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 12:19:02 +02:00
Panic when converting other
I/O errors into our I/O errors (#16160)
# Description I added a debug-only check that makes sure only non-other I/O errors get converted. Since tests run in debug mode, that should help us catch these errors early. I left the check out in release mode on purpose so we don't crash users who have nu as their main shell. It's similar to the debug assertions in the same file that check for unknown spans.
This commit is contained in:
@ -2,16 +2,24 @@ use std::io;
|
||||
use std::process::Command as CommandSys;
|
||||
|
||||
/// Tries to forcefully kill a process by its PID
|
||||
pub fn kill_by_pid(pid: i64) -> io::Result<()> {
|
||||
pub fn kill_by_pid(pid: i64) -> Result<(), KillByPidError> {
|
||||
let mut cmd = build_kill_command(true, std::iter::once(pid), None);
|
||||
|
||||
let output = cmd.output()?;
|
||||
let output = cmd.output().map_err(KillByPidError::Output)?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(io::Error::other("failed to kill process"));
|
||||
match output.status.success() {
|
||||
true => Ok(()),
|
||||
false => Err(KillByPidError::KillProcess),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
/// Error while killing a process forcefully by its PID.
|
||||
pub enum KillByPidError {
|
||||
/// I/O error while capturing the output of the process.
|
||||
Output(io::Error),
|
||||
|
||||
/// Killing the process failed.
|
||||
KillProcess,
|
||||
}
|
||||
|
||||
/// Create a `std::process::Command` for the current target platform, for killing
|
||||
|
Reference in New Issue
Block a user