Skip to content

Commit

Permalink
Use deno_core::JSError in deno (denoland#1855)
Browse files Browse the repository at this point in the history
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 b3b989f
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 416 deletions.
2 changes: 2 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ group("default") {
}

main_extern = [
"core:deno_core",

"$rust_build:ansi_term",
"$rust_build:atty",
"$rust_build:dirs",
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 19 additions & 24 deletions core/js_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ansi.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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),
}
}
}
5 changes: 3 additions & 2 deletions src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}
Expand Down
Loading

0 comments on commit b3b989f

Please sign in to comment.