From f5b40c918c7d602827622d167728a3e7bae87d9d Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 14 Sep 2020 18:48:57 +0200 Subject: refactor: use the 'anyhow' crate instead of 'ErrBox' (#7476) --- cli/signal.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'cli/signal.rs') diff --git a/cli/signal.rs b/cli/signal.rs index 200f8f3bc..b597714f4 100644 --- a/cli/signal.rs +++ b/cli/signal.rs @@ -1,6 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use deno_core::ErrBox; +use deno_core::error::AnyError; + +#[cfg(not(unix))] +use deno_core::error::last_os_error; +#[cfg(not(unix))] +use deno_core::error::type_error; #[cfg(not(unix))] const SIGINT: i32 = 2; @@ -20,37 +25,37 @@ use winapi::{ }; #[cfg(unix)] -pub fn kill(pid: i32, signo: i32) -> Result<(), ErrBox> { +pub fn kill(pid: i32, signo: i32) -> Result<(), AnyError> { use nix::sys::signal::{kill as unix_kill, Signal}; use nix::unistd::Pid; use std::convert::TryFrom; let sig = Signal::try_from(signo)?; - unix_kill(Pid::from_raw(pid), Option::Some(sig)).map_err(ErrBox::from) + unix_kill(Pid::from_raw(pid), Option::Some(sig)).map_err(AnyError::from) } #[cfg(not(unix))] -pub fn kill(pid: i32, signal: i32) -> Result<(), ErrBox> { +pub fn kill(pid: i32, signal: i32) -> Result<(), AnyError> { match signal { SIGINT | SIGKILL | SIGTERM => { if pid <= 0 { - return Err(ErrBox::type_error("unsupported pid")); + return Err(type_error("unsupported pid")); } unsafe { let handle = OpenProcess(PROCESS_TERMINATE, 0, pid as DWORD); if handle.is_null() { - return Err(ErrBox::last_os_error()); + return Err(last_os_error()); } if TerminateProcess(handle, 1) == 0 { CloseHandle(handle); - return Err(ErrBox::last_os_error()); + return Err(last_os_error()); } if CloseHandle(handle) == 0 { - return Err(ErrBox::last_os_error()); + return Err(last_os_error()); } } } _ => { - return Err(ErrBox::type_error("unsupported signal")); + return Err(type_error("unsupported signal")); } } Ok(()) -- cgit v1.2.3