diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-08-26 14:50:21 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-26 08:50:21 -0400 |
commit | 520f9631e09aa720fd8c03513ee8ea967f5ed4b2 (patch) | |
tree | fc3d1bd5182452ca1865a5c2631355e0895af94c /cli/ops/errors.rs | |
parent | 017f88ee99b0fe40221e6af92e0b6a976fbaf2ad (diff) |
bring back json ops (#2815)
Diffstat (limited to 'cli/ops/errors.rs')
-rw-r--r-- | cli/ops/errors.rs | 98 |
1 files changed, 33 insertions, 65 deletions
diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index a27f3656e..cd21a3880 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -1,88 +1,56 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -use super::dispatch_flatbuffers::serialize_response; -use super::utils::*; -use crate::deno_error; +use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::fmt_errors::JSError; -use crate::msg; use crate::source_maps::get_orig_position; use crate::source_maps::CachedMaps; use crate::state::ThreadSafeState; use deno::*; -use flatbuffers::FlatBufferBuilder; use std::collections::HashMap; +#[derive(Deserialize)] +struct FormatErrorArgs { + error: String, +} + pub fn op_format_error( state: &ThreadSafeState, - base: &msg::Base<'_>, - data: Option<PinnedBuf>, -) -> CliOpResult { - assert!(data.is_none()); - let inner = base.inner_as_format_error().unwrap(); - let json_str = inner.error().unwrap(); - let error = JSError::from_json(json_str, &state.ts_compiler); - let error_string = error.to_string(); - - let mut builder = FlatBufferBuilder::new(); - let new_error = builder.create_string(&error_string); - - let inner = msg::FormatErrorRes::create( - &mut builder, - &msg::FormatErrorResArgs { - error: Some(new_error), - }, - ); - - let response_buf = serialize_response( - base.cmd_id(), - &mut builder, - msg::BaseArgs { - inner_type: msg::Any::FormatErrorRes, - inner: Some(inner.as_union_value()), - ..Default::default() - }, - ); + args: Value, + _zero_copy: Option<PinnedBuf>, +) -> Result<JsonOp, ErrBox> { + let args: FormatErrorArgs = serde_json::from_value(args)?; + let error = JSError::from_json(&args.error, &state.ts_compiler); + + Ok(JsonOp::Sync(json!({ + "error": error.to_string(), + }))) +} - ok_buf(response_buf) +#[derive(Deserialize)] +struct ApplySourceMap { + filename: String, + line: i32, + column: i32, } pub fn op_apply_source_map( state: &ThreadSafeState, - base: &msg::Base<'_>, - data: Option<PinnedBuf>, -) -> CliOpResult { - if !base.sync() { - return Err(deno_error::no_async_support()); - } - assert!(data.is_none()); - let inner = base.inner_as_apply_source_map().unwrap(); - let cmd_id = base.cmd_id(); - let filename = inner.filename().unwrap(); - let line = inner.line(); - let column = inner.column(); + args: Value, + _zero_copy: Option<PinnedBuf>, +) -> Result<JsonOp, ErrBox> { + let args: ApplySourceMap = serde_json::from_value(args)?; let mut mappings_map: CachedMaps = HashMap::new(); let (orig_filename, orig_line, orig_column) = get_orig_position( - filename.to_owned(), - line.into(), - column.into(), + args.filename, + args.line.into(), + args.column.into(), &mut mappings_map, &state.ts_compiler, ); - let builder = &mut FlatBufferBuilder::new(); - let msg_args = msg::ApplySourceMapArgs { - filename: Some(builder.create_string(&orig_filename)), - line: orig_line as i32, - column: orig_column as i32, - }; - let res_inner = msg::ApplySourceMap::create(builder, &msg_args); - ok_buf(serialize_response( - cmd_id, - builder, - msg::BaseArgs { - inner: Some(res_inner.as_union_value()), - inner_type: msg::Any::ApplySourceMap, - ..Default::default() - }, - )) + Ok(JsonOp::Sync(json!({ + "filename": orig_filename.to_string(), + "line": orig_line as u32, + "column": orig_column as u32, + }))) } |