remove useless KillRunningServerError type,

directly use `ExecuteProxyError` for `kill_running_server` error result
This commit is contained in:
Gwen Lg 2025-07-02 13:23:44 +02:00
parent 7f7e3c1222
commit e3789b2cdd

View file

@ -599,10 +599,10 @@ pub(crate) enum ExecuteProxyError {
path: PathBuf, path: PathBuf,
}, },
#[error("Failed to kill pid '{pid}'")] #[error("Failed to kill existing server with pid '{pid}'")]
KillRunningServer { KillRunningServer {
#[source] #[source]
source: KillRunningServerError, source: std::io::Error,
pid: u32, pid: u32,
}, },
@ -657,8 +657,7 @@ pub(crate) fn execute_proxy(
"proxy found server already running with PID {}. Killing process and cleaning up files...", "proxy found server already running with PID {}. Killing process and cleaning up files...",
pid pid
); );
kill_running_server(pid, &server_paths) kill_running_server(pid, &server_paths)?;
.map_err(|source| ExecuteProxyError::KillRunningServer { source, pid })?;
} }
spawn_server(&server_paths).map_err(ExecuteProxyError::SpawnServer)?; spawn_server(&server_paths).map_err(ExecuteProxyError::SpawnServer)?;
@ -716,16 +715,12 @@ pub(crate) fn execute_proxy(
Ok(()) Ok(())
} }
#[derive(Debug, Error)] fn kill_running_server(pid: u32, paths: &ServerPaths) -> Result<(), ExecuteProxyError> {
#[error("failed to kill existing server")]
pub(crate) struct KillRunningServerError(std::io::Error);
fn kill_running_server(pid: u32, paths: &ServerPaths) -> Result<(), KillRunningServerError> {
log::info!("killing existing server with PID {}", pid); log::info!("killing existing server with PID {}", pid);
std::process::Command::new("kill") std::process::Command::new("kill")
.arg(pid.to_string()) .arg(pid.to_string())
.output() .output()
.map_err(KillRunningServerError)?; .map_err(|source| ExecuteProxyError::KillRunningServer { source, pid })?;
for file in [ for file in [
&paths.pid_file, &paths.pid_file,