summaryrefslogtreecommitdiff
path: root/cli/ops/signal.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-02-23 14:51:29 -0500
committerGitHub <noreply@github.com>2020-02-23 14:51:29 -0500
commit4e1abb4f3a1fbdac25b1e7db0588572e4d5a6579 (patch)
tree644ace7dc1acac7b09bfab037e0ca589fa11987b /cli/ops/signal.rs
parent45eb2f9b37c2c7498c58eb45f76667aaa4a7d731 (diff)
refactor: use OpError instead of ErrBox for errors in ops (#4058)
To better reflect changes in error types in JS from #3662 this PR changes default error type used in ops from "ErrBox" to "OpError". "OpError" is a type that can be sent over to JSON; it has all information needed to construct error in JavaScript. That made "GetErrorKind" trait useless and so it was removed altogether. To provide compatibility with previous use of "ErrBox" an implementation of "From<ErrBox> for OpError" was added, however, it is an escape hatch and ops implementors should strive to use "OpError" directly.
Diffstat (limited to 'cli/ops/signal.rs')
-rw-r--r--cli/ops/signal.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/cli/ops/signal.rs b/cli/ops/signal.rs
index 8d70f9fe8..07a9cd527 100644
--- a/cli/ops/signal.rs
+++ b/cli/ops/signal.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{JsonOp, Value};
+use crate::op_error::OpError;
use crate::ops::json_op;
use crate::state::State;
use deno_core::*;
@@ -7,8 +8,6 @@ use deno_core::*;
#[cfg(unix)]
use super::dispatch_json::Deserialize;
#[cfg(unix)]
-use crate::deno_error::bad_resource;
-#[cfg(unix)]
use futures::future::{poll_fn, FutureExt};
#[cfg(unix)]
use serde_json;
@@ -54,7 +53,7 @@ fn op_signal_bind(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: BindSignalArgs = serde_json::from_value(args)?;
let mut state = state.borrow_mut();
let rid = state.resource_table.add(
@@ -74,7 +73,7 @@ fn op_signal_poll(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: SignalArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let state_ = state.clone();
@@ -99,7 +98,7 @@ pub fn op_signal_unbind(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: SignalArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let mut state = state.borrow_mut();
@@ -111,7 +110,10 @@ pub fn op_signal_unbind(
waker.clone().wake();
}
}
- state.resource_table.close(rid).ok_or_else(bad_resource)?;
+ state
+ .resource_table
+ .close(rid)
+ .ok_or_else(OpError::bad_resource)?;
Ok(JsonOp::Sync(json!({})))
}
@@ -120,7 +122,7 @@ pub fn op_signal_bind(
_state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
unimplemented!();
}
@@ -129,7 +131,7 @@ fn op_signal_unbind(
_state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
unimplemented!();
}
@@ -138,6 +140,6 @@ fn op_signal_poll(
_state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
unimplemented!();
}