From 4e1abb4f3a1fbdac25b1e7db0588572e4d5a6579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 23 Feb 2020 14:51:29 -0500 Subject: 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 for OpError" was added, however, it is an escape hatch and ops implementors should strive to use "OpError" directly. --- cli/compilers/ts.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cli/compilers/ts.rs') diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index 73f5a11fb..2113aceb0 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -9,6 +9,7 @@ use crate::file_fetcher::SourceFile; use crate::file_fetcher::SourceFileFetcher; use crate::global_state::GlobalState; use crate::msg; +use crate::op_error::OpError; use crate::ops::JsonResult; use crate::source_maps::SourceMapGetter; use crate::startup_data; @@ -633,7 +634,9 @@ async fn execute_in_thread_json( req_msg: Buf, global_state: GlobalState, ) -> JsonResult { - let msg = execute_in_thread(global_state, req_msg).await?; + let msg = execute_in_thread(global_state, req_msg) + .await + .map_err(|e| OpError::other(e.to_string()))?; let json_str = std::str::from_utf8(&msg).unwrap(); Ok(json!(json_str)) } -- cgit v1.2.3