summaryrefslogtreecommitdiff
path: root/cli/ops/errors.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-08-24 15:02:42 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-08-24 06:02:42 -0700
commit79f82cf10ed1dbf91346994250d7311a4d74377a (patch)
treeb00755d666198b9c66264a3c240f849096951e2f /cli/ops/errors.rs
parent5b2baa5c990fbeae747e952c5dcd7a5369e950b1 (diff)
port ops to JSON: compiler, errors, fetch, files (#2804)
Diffstat (limited to 'cli/ops/errors.rs')
-rw-r--r--cli/ops/errors.rs98
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,
+ })))
}