summaryrefslogtreecommitdiff
path: root/cli/ops/web_worker.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/web_worker.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/web_worker.rs')
-rw-r--r--cli/ops/web_worker.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/cli/ops/web_worker.rs b/cli/ops/web_worker.rs
index e22c0f221..db3ecd6ce 100644
--- a/cli/ops/web_worker.rs
+++ b/cli/ops/web_worker.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 crate::worker::WorkerEvent;
@@ -13,17 +14,17 @@ use std::convert::From;
pub fn web_worker_op<D>(
sender: mpsc::Sender<WorkerEvent>,
dispatcher: D,
-) -> impl Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, ErrBox>
+) -> impl Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>
where
D: Fn(
&mpsc::Sender<WorkerEvent>,
Value,
Option<ZeroCopyBuf>,
- ) -> Result<JsonOp, ErrBox>,
+ ) -> Result<JsonOp, OpError>,
{
- move |args: Value, zero_copy: Option<ZeroCopyBuf>| -> Result<JsonOp, ErrBox> {
- dispatcher(&sender, args, zero_copy)
- }
+ move |args: Value,
+ zero_copy: Option<ZeroCopyBuf>|
+ -> Result<JsonOp, OpError> { dispatcher(&sender, args, zero_copy) }
}
pub fn init(i: &mut Isolate, s: &State, sender: &mpsc::Sender<WorkerEvent>) {
@@ -45,7 +46,7 @@ fn op_worker_post_message(
sender: &mpsc::Sender<WorkerEvent>,
_args: Value,
data: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let d = Vec::from(data.unwrap().as_ref()).into_boxed_slice();
let mut sender = sender.clone();
let fut = sender.send(WorkerEvent::Message(d));
@@ -58,7 +59,7 @@ fn op_worker_close(
sender: &mpsc::Sender<WorkerEvent>,
_args: Value,
_data: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let mut sender = sender.clone();
sender.close_channel();
Ok(JsonOp::Sync(json!({})))