diff options
Diffstat (limited to 'cli/ops/dispatch_json.rs')
-rw-r--r-- | cli/ops/dispatch_json.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index 6e0eddac8..031e10c51 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -24,17 +24,19 @@ pub enum JsonOp { } pub fn serialize_result( - rust_err_to_json_fn: &'static dyn deno_core::RustErrToJsonFn, promise_id: Option<u64>, result: JsonResult, + get_error_class_fn: deno_core::GetErrorClassFn, ) -> Buf { let value = match result { Ok(v) => json!({ "ok": v, "promiseId": promise_id }), - Err(err) => { - let serialized_err = (&rust_err_to_json_fn)(&err); - let err_value: Value = serde_json::from_slice(&serialized_err).unwrap(); - json!({ "err": err_value, "promiseId": promise_id }) - } + Err(err) => json!({ + "err": { + "className": (get_error_class_fn)(&err), + "message": err.to_string() + }, + "promiseId": promise_id + }), }; serde_json::to_vec(&value).unwrap().into_boxed_slice() } @@ -56,12 +58,13 @@ where ) -> Result<JsonOp, ErrBox>, { move |isolate_state: &mut CoreIsolateState, zero_copy: &mut [ZeroCopyBuf]| { + let get_error_class_fn = isolate_state.get_error_class_fn; + assert!(!zero_copy.is_empty(), "Expected JSON string at position 0"); - let rust_err_to_json_fn = isolate_state.rust_err_to_json_fn; let async_args: AsyncArgs = match serde_json::from_slice(&zero_copy[0]) { Ok(args) => args, Err(e) => { - let buf = serialize_result(rust_err_to_json_fn, None, Err(e.into())); + let buf = serialize_result(None, Err(e.into()), get_error_class_fn); return Op::Sync(buf); } }; @@ -77,18 +80,18 @@ where Ok(JsonOp::Sync(sync_value)) => { assert!(promise_id.is_none()); Op::Sync(serialize_result( - rust_err_to_json_fn, promise_id, Ok(sync_value), + get_error_class_fn, )) } Ok(JsonOp::Async(fut)) => { assert!(promise_id.is_some()); let fut2 = fut.then(move |result| { futures::future::ready(serialize_result( - rust_err_to_json_fn, promise_id, result, + get_error_class_fn, )) }); Op::Async(fut2.boxed_local()) @@ -97,16 +100,16 @@ where assert!(promise_id.is_some()); let fut2 = fut.then(move |result| { futures::future::ready(serialize_result( - rust_err_to_json_fn, promise_id, result, + get_error_class_fn, )) }); Op::AsyncUnref(fut2.boxed_local()) } Err(sync_err) => { let buf = - serialize_result(rust_err_to_json_fn, promise_id, Err(sync_err)); + serialize_result(promise_id, Err(sync_err), get_error_class_fn); if is_sync { Op::Sync(buf) } else { |