Skip to content
Permalink
Browse files

Use deno_core::JSError in deno (#1855)

src/js_errors.rs takes care of source maps and color while
core/js_errors.rs is just the basic struct.
  • Loading branch information...
ry committed Feb 28, 2019
1 parent b0c7b54 commit b3b989ffdca61403cdd7ca94bd9256159864469e
Showing with 139 additions and 416 deletions.
  1. +2 −0 BUILD.gn
  2. +1 −0 Cargo.lock
  3. +2 −0 Cargo.toml
  4. +19 −24 core/js_errors.rs
  5. +1 −1 core/lib.rs
  6. +1 −0 src/ansi.rs
  7. +3 −4 src/errors.rs
  8. +3 −2 src/isolate.rs
  9. +99 −380 src/js_errors.rs
  10. +5 −3 src/ops.rs
  11. +3 −2 src/workers.rs
@@ -20,6 +20,8 @@ group("default") {
}

main_extern = [
"core:deno_core",

"$rust_build:ansi_term",
"$rust_build:atty",
"$rust_build:dirs",

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -17,6 +17,8 @@ version = "0.3.1"
edition = "2018"

[dependencies]
deno_core = { path = "./core" }

ansi_term = "0.11.0"
atty = "0.2.11"
dirs = "1.0.5"
@@ -73,32 +73,27 @@ impl fmt::Display for JSError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.script_resource_name.is_some() {
let script_resource_name = self.script_resource_name.as_ref().unwrap();
// Avoid showing internal code from gen/bundle/main.js
if script_resource_name != "gen/bundle/main.js"
&& script_resource_name != "gen/bundle/compiler.js"
{
if self.line_number.is_some() && self.start_column.is_some() {
assert!(self.line_number.is_some());
assert!(self.start_column.is_some());
let script_line_column = format_script_line_column(
script_resource_name,
self.line_number.unwrap() - 1,
self.start_column.unwrap() - 1,
);
write!(f, "{}", script_line_column)?;
}
if self.source_line.is_some() {
write!(f, "\n{}\n", self.source_line.as_ref().unwrap())?;
let mut s = String::new();
for i in 0..self.end_column.unwrap() {
if i >= self.start_column.unwrap() {
s.push('^');
} else {
s.push(' ');
}
if self.line_number.is_some() && self.start_column.is_some() {
assert!(self.line_number.is_some());
assert!(self.start_column.is_some());
let script_line_column = format_script_line_column(
script_resource_name,
self.line_number.unwrap() - 1,
self.start_column.unwrap() - 1,
);
write!(f, "{}", script_line_column)?;
}
if self.source_line.is_some() {
write!(f, "\n{}\n", self.source_line.as_ref().unwrap())?;
let mut s = String::new();
for i in 0..self.end_column.unwrap() {
if i >= self.start_column.unwrap() {
s.push('^');
} else {
s.push(' ');
}
writeln!(f, "{}", s)?;
}
writeln!(f, "{}", s)?;
}
}

@@ -7,7 +7,7 @@ mod js_errors;
mod libdeno;
mod shared;

pub use crate::js_errors::JSError;
pub use crate::js_errors::*;
pub use crate::libdeno::deno_buf;
pub use crate::shared::*;
use futures::Async;
@@ -1,3 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use ansi_term::Color::Fixed;
use ansi_term::Color::Red;
use ansi_term::Style;
@@ -1,9 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.

use crate::js_errors::JSError;
use crate::js_errors::JSErrorColor;
pub use crate::msg::ErrorKind;
use crate::resolve_addr::ResolveAddrError;

use deno_core::JSError;
use hyper;
use std;
use std::fmt;
@@ -202,7 +201,7 @@ impl fmt::Display for RustOrJsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RustOrJsError::Rust(e) => e.fmt(f),
RustOrJsError::Js(e) => e.fmt(f),
RustOrJsError::Js(e) => JSErrorColor(e).fmt(f),
}
}
}
@@ -12,12 +12,13 @@ use crate::errors::DenoError;
use crate::errors::DenoResult;
use crate::errors::RustOrJsError;
use crate::flags;
use crate::js_errors::JSError;
use crate::js_errors::apply_source_map;
use crate::libdeno;
use crate::modules::Modules;
use crate::msg;
use crate::permissions::DenoPermissions;
use crate::tokio_util;
use deno_core::JSError;
use futures::sync::mpsc as async_mpsc;
use futures::Future;
use libc::c_char;
@@ -250,7 +251,7 @@ impl Isolate {
let v8_exception = cstr.to_str().unwrap();
debug!("v8_exception\n{}\n", v8_exception);
let js_error = JSError::from_v8_exception(v8_exception).unwrap();
let js_error_mapped = js_error.apply_source_map(&self.state.dir);
let js_error_mapped = apply_source_map(&js_error, &self.state.dir);
Some(js_error_mapped)
}
}
Oops, something went wrong.

0 comments on commit b3b989f

Please sign in to comment.
You can’t perform that action at this time.