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:
Piepmatz
2025-07-16 00:55:02 +02:00
committed by GitHub
parent 2df00ff498
commit db1ffe57d3
3 changed files with 64 additions and 12 deletions

View File

@ -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