diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-09-14 18:48:57 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-09-15 01:50:52 +0200 |
commit | f5b40c918c7d602827622d167728a3e7bae87d9d (patch) | |
tree | fb51722e043f4d6bce64a2c7e897cce4ead06c82 /cli/signal.rs | |
parent | 3da20d19a14ab6838897d281f1b11e49d68bd1a7 (diff) |
refactor: use the 'anyhow' crate instead of 'ErrBox' (#7476)
Diffstat (limited to 'cli/signal.rs')
-rw-r--r-- | cli/signal.rs | 23 |
1 files changed, 14 insertions, 9 deletions
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(()) |