Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid show confusing lines in gen/bundle/main.js that throws error #1502

Merged
merged 1 commit into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/js_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,31 @@ impl ToString for StackFrame {

impl ToString for JSError {
fn to_string(&self) -> String {
// TODO use fewer clones.
// TODO Improve the formatting of these error messages.
let mut s = String::new();

if self.script_resource_name.is_some() {
s.push_str(&self.script_resource_name.clone().unwrap());
}
if self.line_number.is_some() {
s.push_str(&format!(
":{}:{}",
self.line_number.unwrap(),
self.start_column.unwrap()
));
assert!(self.start_column.is_some());
}
if self.source_line.is_some() {
s.push_str("\n");
s.push_str(&self.source_line.clone().unwrap());
s.push_str("\n\n");
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" {
s.push_str(script_resource_name);
if self.line_number.is_some() {
s.push_str(&format!(
":{}:{}",
self.line_number.unwrap(),
self.start_column.unwrap()
));
assert!(self.start_column.is_some());
}
if self.source_line.is_some() {
s.push_str("\n");
s.push_str(self.source_line.as_ref().unwrap());
s.push_str("\n\n");
}
}
}

s.push_str(&self.message.clone());
s.push_str(&self.message);

for frame in &self.frames {
s.push_str("\n");
Expand Down
3 changes: 2 additions & 1 deletion tests/error_004_missing_module.ts.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[WILDCARD]NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
Compiling [WILDCARD]tests/error_004_missing_module.ts
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
at DenoError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeThrowError ([WILDCARD]/js/errors.ts:[WILDCARD])
Expand Down
3 changes: 2 additions & 1 deletion tests/error_006_import_ext_failure.ts.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[WILDCARD]NotFound: Cannot resolve module "./non-existent" from "[WILDCARD]/tests/error_006_import_ext_failure.ts"
Compiling [WILDCARD]tests/error_006_import_ext_failure.ts
NotFound: Cannot resolve module "./non-existent" from "[WILDCARD]/tests/error_006_import_ext_failure.ts"
at DenoError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeThrowError ([WILDCARD]/js/errors.ts:[WILDCARD])
Expand Down