summaryrefslogtreecommitdiff
path: root/cli/ops/dispatch_minimal.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/dispatch_minimal.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/dispatch_minimal.rs')
-rw-r--r--cli/ops/dispatch_minimal.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/cli/ops/dispatch_minimal.rs b/cli/ops/dispatch_minimal.rs
index 0bff571f2..2dd4db9ef 100644
--- a/cli/ops/dispatch_minimal.rs
+++ b/cli/ops/dispatch_minimal.rs
@@ -4,19 +4,17 @@
//! alternative to flatbuffers using a very simple list of int32s to lay out
//! messages. The first i32 is used to determine if a message a flatbuffer
//! message or a "minimal" message.
-use crate::deno_error::ErrorKind;
-use crate::deno_error::GetErrorKind;
+use crate::op_error::OpError;
use byteorder::{LittleEndian, WriteBytesExt};
use deno_core::Buf;
use deno_core::CoreOp;
-use deno_core::ErrBox;
use deno_core::Op;
use deno_core::ZeroCopyBuf;
use futures::future::FutureExt;
use std::future::Future;
use std::pin::Pin;
-pub type MinimalOp = dyn Future<Output = Result<i32, ErrBox>>;
+pub type MinimalOp = dyn Future<Output = Result<i32, OpError>>;
#[derive(Copy, Clone, Debug, PartialEq)]
// This corresponds to RecordMinimal on the TS side.
@@ -121,14 +119,12 @@ where
let mut record = match parse_min_record(control) {
Some(r) => r,
None => {
+ let e = OpError::type_error("Unparsable control buffer".to_string());
let error_record = ErrorRecord {
promise_id: 0,
arg: -1,
- error_code: ErrorKind::TypeError as i32,
- error_message: "Unparsable control buffer"
- .to_string()
- .as_bytes()
- .to_owned(),
+ error_code: e.kind as i32,
+ error_message: e.msg.as_bytes().to_owned(),
};
return Op::Sync(error_record.into());
}
@@ -148,8 +144,8 @@ where
let error_record = ErrorRecord {
promise_id: record.promise_id,
arg: -1,
- error_code: err.kind() as i32,
- error_message: err.to_string().as_bytes().to_owned(),
+ error_code: err.kind as i32,
+ error_message: err.msg.as_bytes().to_owned(),
};
Ok(error_record.into())
}