diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-02-23 14:51:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-23 14:51:29 -0500 |
| commit | 4e1abb4f3a1fbdac25b1e7db0588572e4d5a6579 (patch) | |
| tree | 644ace7dc1acac7b09bfab037e0ca589fa11987b /cli/ops/worker_host.rs | |
| parent | 45eb2f9b37c2c7498c58eb45f76667aaa4a7d731 (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/worker_host.rs')
| -rw-r--r-- | cli/ops/worker_host.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs index c3b907673..910f44459 100644 --- a/cli/ops/worker_host.rs +++ b/cli/ops/worker_host.rs @@ -1,10 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; -use crate::deno_error::DenoError; -use crate::deno_error::ErrorKind; use crate::fmt_errors::JSError; use crate::futures::SinkExt; use crate::global_state::GlobalState; +use crate::op_error::OpError; use crate::ops::json_op; use crate::permissions::DenoPermissions; use crate::startup_data; @@ -147,7 +146,7 @@ fn op_create_worker( state: &State, args: Value, _data: Option<ZeroCopyBuf>, -) -> Result<JsonOp, ErrBox> { +) -> Result<JsonOp, OpError> { let args: CreateWorkerArgs = serde_json::from_value(args)?; let specifier = args.specifier.clone(); @@ -175,7 +174,8 @@ fn op_create_worker( module_specifier, has_source_code, source_code, - )?; + ) + .map_err(|e| OpError::other(e.to_string()))?; // At this point all interactions with worker happen using thread // safe handler returned from previous function call let mut parent_state = parent_state.borrow_mut(); @@ -197,7 +197,7 @@ fn op_host_terminate_worker( state: &State, args: Value, _data: Option<ZeroCopyBuf>, -) -> Result<JsonOp, ErrBox> { +) -> Result<JsonOp, OpError> { let args: WorkerArgs = serde_json::from_value(args)?; let id = args.id as u32; let mut state = state.borrow_mut(); @@ -242,7 +242,7 @@ fn op_host_get_message( state: &State, args: Value, _data: Option<ZeroCopyBuf>, -) -> Result<JsonOp, ErrBox> { +) -> Result<JsonOp, OpError> { let args: WorkerArgs = serde_json::from_value(args)?; let id = args.id as u32; let worker_handle = { @@ -274,7 +274,7 @@ fn op_host_post_message( state: &State, args: Value, data: Option<ZeroCopyBuf>, -) -> Result<JsonOp, ErrBox> { +) -> Result<JsonOp, OpError> { let args: WorkerArgs = serde_json::from_value(args)?; let id = args.id as u32; let msg = Vec::from(data.unwrap().as_ref()).into_boxed_slice(); @@ -285,7 +285,7 @@ fn op_host_post_message( state.workers.get(&id).expect("No worker handle found"); let fut = worker_handle .post_message(msg) - .map_err(|e| DenoError::new(ErrorKind::Other, e.to_string())); + .map_err(|e| OpError::other(e.to_string())); futures::executor::block_on(fut)?; Ok(JsonOp::Sync(json!({}))) } |
