diff options
Diffstat (limited to 'cli/ops/errors.rs')
-rw-r--r-- | cli/ops/errors.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index 4dd4f1ca1..b5cc75f7a 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -1,5 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; +use crate::diagnostics::Diagnostic; use crate::fmt_errors::JSError; use crate::op_error::OpError; use crate::ops::json_op; @@ -18,6 +19,10 @@ pub fn init(i: &mut Isolate, s: &State) { "format_error", s.core_op(json_op(s.stateful_op(op_format_error))), ); + i.register_op( + "format_diagnostic", + s.core_op(json_op(s.stateful_op(op_format_diagnostic))), + ); } #[derive(Deserialize)] @@ -68,3 +73,15 @@ fn op_apply_source_map( "column": orig_column as u32, }))) } + +fn op_format_diagnostic( + _state: &State, + args: Value, + _zero_copy: Option<ZeroCopyBuf>, +) -> Result<JsonOp, OpError> { + if let Some(diagnostic) = Diagnostic::from_json_value(&args) { + Ok(JsonOp::Sync(json!(diagnostic.to_string()))) + } else { + Err(OpError::type_error("bad diagnostic".to_string())) + } +} |