From 183e81cc8ac1d114a3a2e8dbcbe31c462834e046 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Sun, 26 Dec 2021 05:36:22 +0100 Subject: [PATCH 1/9] error cause --- cli/fmt_errors.rs | 10 +++++ cli/source_maps.rs | 1 + core/error.rs | 95 ++++++++++++++++++++++++++-------------------- 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index 6c4a4893afe539..53d77b73d68cca 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -131,6 +131,7 @@ fn format_frame(frame: &JsStackFrame) -> String { fn format_stack( is_error: bool, message_line: &str, + cause: Option<&str>, source_line: Option<&str>, start_column: Option, end_column: Option, @@ -139,6 +140,14 @@ fn format_stack( ) -> String { let mut s = String::new(); s.push_str(&format!("{:indent$}{}", "", message_line, indent = level)); + if let Some(cause) = cause { + s.push_str(&format!( + "\n{:indent$}Caused by: {}", + "", + cause, + indent = level + )); + } s.push_str(&format_maybe_source_line( source_line, start_column, @@ -268,6 +277,7 @@ impl fmt::Display for PrettyJsError { &format_stack( true, &self.0.message, + self.0.cause.as_deref(), self.0.source_line.as_deref(), self.0.start_column, self.0.end_column, diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 74c390893d403f..486d89ff538838 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -81,6 +81,7 @@ pub fn apply_source_map( JsError { message: js_error.message.clone(), + cause: js_error.cause.clone(), source_line, script_resource_name, line_number, diff --git a/core/error.rs b/core/error.rs index 332bc5c514a1f1..2e7c996d68ffa8 100644 --- a/core/error.rs +++ b/core/error.rs @@ -92,6 +92,7 @@ pub fn get_custom_error_class(error: &Error) -> Option<&'static str> { #[derive(Debug, PartialEq, Clone)] pub struct JsError { pub message: String, + pub cause: Option, pub source_line: Option, pub script_resource_name: Option, pub line_number: Option, @@ -161,6 +162,7 @@ fn get_property<'a>( pub(crate) struct NativeJsError { pub name: Option, pub message: Option, + pub cause: Option, // Warning! .stack is special so handled by itself // stack: Option, } @@ -180,53 +182,62 @@ impl JsError { let msg = v8::Exception::create_message(scope, exception); - let (message, frames, stack) = if is_instance_of_error(scope, exception) { - // The exception is a JS Error object. - let exception: v8::Local = exception.try_into().unwrap(); - - let e: NativeJsError = - serde_v8::from_v8(scope, exception.into()).unwrap(); - // Get the message by formatting error.name and error.message. - let name = e.name.unwrap_or_else(|| "Error".to_string()); - let message_prop = e.message.unwrap_or_else(|| "".to_string()); - let message = if !name.is_empty() && !message_prop.is_empty() { - format!("Uncaught {}: {}", name, message_prop) - } else if !name.is_empty() { - format!("Uncaught {}", name) - } else if !message_prop.is_empty() { - format!("Uncaught {}", message_prop) + let (message, frames, stack, cause) = + if is_instance_of_error(scope, exception) { + // The exception is a JS Error object. + let exception: v8::Local = exception.try_into().unwrap(); + + let e: NativeJsError = + serde_v8::from_v8(scope, exception.into()).unwrap(); + // Get the message by formatting error.name and error.message. + let name = e.name.unwrap_or_else(|| "Error".to_string()); + let message_prop = e.message.unwrap_or_else(|| "".to_string()); + let message = if !name.is_empty() && !message_prop.is_empty() { + format!("Uncaught {}: {}", name, message_prop) + } else if !name.is_empty() { + format!("Uncaught {}", name) + } else if !message_prop.is_empty() { + format!("Uncaught {}", message_prop) + } else { + "Uncaught".to_string() + }; + + // Access error.stack to ensure that prepareStackTrace() has been called. + // This should populate error.__callSiteEvals. + let stack = get_property(scope, exception, "stack"); + let stack: Option> = + stack.and_then(|s| s.try_into().ok()); + let stack = stack.map(|s| s.to_rust_string_lossy(scope)); + + // Read an array of structured frames from error.__callSiteEvals. + let frames_v8 = get_property(scope, exception, "__callSiteEvals"); + // Ignore non-array values + let frames_v8: Option> = + frames_v8.and_then(|a| a.try_into().ok()); + + // Convert them into Vec + let frames: Vec = match frames_v8 { + Some(frames_v8) => { + serde_v8::from_v8(scope, frames_v8.into()).unwrap() + } + None => vec![], + }; + (message, frames, stack, e.cause) } else { - "Uncaught".to_string() + // The exception is not a JS Error object. + // Get the message given by V8::Exception::create_message(), and provide + // empty frames. + ( + msg.get(scope).to_rust_string_lossy(scope), + vec![], + None, + None, + ) }; - // Access error.stack to ensure that prepareStackTrace() has been called. - // This should populate error.__callSiteEvals. - let stack = get_property(scope, exception, "stack"); - let stack: Option> = - stack.and_then(|s| s.try_into().ok()); - let stack = stack.map(|s| s.to_rust_string_lossy(scope)); - - // Read an array of structured frames from error.__callSiteEvals. - let frames_v8 = get_property(scope, exception, "__callSiteEvals"); - // Ignore non-array values - let frames_v8: Option> = - frames_v8.and_then(|a| a.try_into().ok()); - - // Convert them into Vec - let frames: Vec = match frames_v8 { - Some(frames_v8) => serde_v8::from_v8(scope, frames_v8.into()).unwrap(), - None => vec![], - }; - (message, frames, stack) - } else { - // The exception is not a JS Error object. - // Get the message given by V8::Exception::create_message(), and provide - // empty frames. - (msg.get(scope).to_rust_string_lossy(scope), vec![], None) - }; - Self { message, + cause, script_resource_name: msg .get_script_resource_name(scope) .and_then(|v| v8::Local::::try_from(v).ok()) From b0e3e0f18cea2a88878c4ba3159e95eed0e67d33 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 27 Dec 2021 22:09:10 +0100 Subject: [PATCH 2/9] fix up --- cli/fmt_errors.rs | 20 +++++++++++--------- core/error.rs | 19 ++++++++++++++----- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index 53d77b73d68cca..acd7a6ff7b2b0f 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -140,14 +140,6 @@ fn format_stack( ) -> String { let mut s = String::new(); s.push_str(&format!("{:indent$}{}", "", message_line, indent = level)); - if let Some(cause) = cause { - s.push_str(&format!( - "\n{:indent$}Caused by: {}", - "", - cause, - indent = level - )); - } s.push_str(&format_maybe_source_line( source_line, start_column, @@ -163,6 +155,14 @@ fn format_stack( indent = level )); } + if let Some(cause) = cause { + s.push_str(&format!( + "\n{:indent$}Caused by: {}", + "", + cause, + indent = level + )); + } s } @@ -271,13 +271,15 @@ impl fmt::Display for PrettyJsError { )]; } + let cause = self.0.cause.clone().map(|cause| format!("{}", PrettyJsError(cause))); + write!( f, "{}", &format_stack( true, &self.0.message, - self.0.cause.as_deref(), + cause.as_deref(), self.0.source_line.as_deref(), self.0.start_column, self.0.end_column, diff --git a/core/error.rs b/core/error.rs index 2e7c996d68ffa8..4dedc4cae8e5ba 100644 --- a/core/error.rs +++ b/core/error.rs @@ -92,7 +92,7 @@ pub fn get_custom_error_class(error: &Error) -> Option<&'static str> { #[derive(Debug, PartialEq, Clone)] pub struct JsError { pub message: String, - pub cause: Option, + pub cause: Box>, pub source_line: Option, pub script_resource_name: Option, pub line_number: Option, @@ -162,7 +162,6 @@ fn get_property<'a>( pub(crate) struct NativeJsError { pub name: Option, pub message: Option, - pub cause: Option, // Warning! .stack is special so handled by itself // stack: Option, } @@ -186,7 +185,10 @@ impl JsError { if is_instance_of_error(scope, exception) { // The exception is a JS Error object. let exception: v8::Local = exception.try_into().unwrap(); - + let cause_key = v8::String::new(scope, "cause").unwrap(); + let cause = exception.get(scope, cause_key.into()); + let undefined = v8::undefined(scope); + exception.set(scope, cause_key.into(), undefined.into()); let e: NativeJsError = serde_v8::from_v8(scope, exception.into()).unwrap(); // Get the message by formatting error.name and error.message. @@ -201,6 +203,13 @@ impl JsError { } else { "Uncaught".to_string() }; + let cause = Box::new(cause.and_then(|cause| { + if cause.is_undefined() { + None + } else { + Some(JsError::from_v8_exception(scope, cause)) + } + })); // Access error.stack to ensure that prepareStackTrace() has been called. // This should populate error.__callSiteEvals. @@ -222,7 +231,7 @@ impl JsError { } None => vec![], }; - (message, frames, stack, e.cause) + (message, frames, stack, cause) } else { // The exception is not a JS Error object. // Get the message given by V8::Exception::create_message(), and provide @@ -231,7 +240,7 @@ impl JsError { msg.get(scope).to_rust_string_lossy(scope), vec![], None, - None, + Box::new(None), ) }; From 8b3bd0a96e43f1729952f449d3532223d4349d10 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 27 Dec 2021 22:14:59 +0100 Subject: [PATCH 3/9] fmt --- cli/fmt_errors.rs | 7 ++++++- cli/source_maps.rs | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index acd7a6ff7b2b0f..dfa231cbe9e093 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -128,6 +128,7 @@ fn format_frame(frame: &JsStackFrame) -> String { result } +#[allow(clippy::too_many_arguments)] fn format_stack( is_error: bool, message_line: &str, @@ -271,7 +272,11 @@ impl fmt::Display for PrettyJsError { )]; } - let cause = self.0.cause.clone().map(|cause| format!("{}", PrettyJsError(cause))); + let cause = self + .0 + .cause + .clone() + .map(|cause| format!("{}", PrettyJsError(cause))); write!( f, diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 486d89ff538838..e2f8463682117d 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -239,6 +239,7 @@ mod tests { fn apply_source_map_line() { let e = JsError { message: "TypeError: baz".to_string(), + cause: Box::new(None), source_line: Some("foo".to_string()), script_resource_name: Some("foo_bar.ts".to_string()), line_number: Some(4), From 0fae5ef563da58f7cbcc76f781df88426d84e2f1 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 27 Dec 2021 22:26:27 +0100 Subject: [PATCH 4/9] clean up --- cli/fmt_errors.rs | 4 ++-- cli/source_maps.rs | 2 +- core/error.rs | 15 ++++++--------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index dfa231cbe9e093..5e4ce1d4f8ec4d 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -275,8 +275,8 @@ impl fmt::Display for PrettyJsError { let cause = self .0 .cause - .clone() - .map(|cause| format!("{}", PrettyJsError(cause))); + .as_ref() + .map(|cause| format!("{}", PrettyJsError(*cause.clone()))); write!( f, diff --git a/cli/source_maps.rs b/cli/source_maps.rs index e2f8463682117d..4d13b01df7d51f 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -239,7 +239,7 @@ mod tests { fn apply_source_map_line() { let e = JsError { message: "TypeError: baz".to_string(), - cause: Box::new(None), + cause: None, source_line: Some("foo".to_string()), script_resource_name: Some("foo_bar.ts".to_string()), line_number: Some(4), diff --git a/core/error.rs b/core/error.rs index 4dedc4cae8e5ba..2ae4986ea20adf 100644 --- a/core/error.rs +++ b/core/error.rs @@ -92,7 +92,7 @@ pub fn get_custom_error_class(error: &Error) -> Option<&'static str> { #[derive(Debug, PartialEq, Clone)] pub struct JsError { pub message: String, - pub cause: Box>, + pub cause: Option>, pub source_line: Option, pub script_resource_name: Option, pub line_number: Option, @@ -185,10 +185,7 @@ impl JsError { if is_instance_of_error(scope, exception) { // The exception is a JS Error object. let exception: v8::Local = exception.try_into().unwrap(); - let cause_key = v8::String::new(scope, "cause").unwrap(); - let cause = exception.get(scope, cause_key.into()); - let undefined = v8::undefined(scope); - exception.set(scope, cause_key.into(), undefined.into()); + let cause = get_property(scope, exception, "cause"); let e: NativeJsError = serde_v8::from_v8(scope, exception.into()).unwrap(); // Get the message by formatting error.name and error.message. @@ -203,13 +200,13 @@ impl JsError { } else { "Uncaught".to_string() }; - let cause = Box::new(cause.and_then(|cause| { + let cause = cause.and_then(|cause| { if cause.is_undefined() { None } else { - Some(JsError::from_v8_exception(scope, cause)) + Some(Box::new(JsError::from_v8_exception(scope, cause))) } - })); + }); // Access error.stack to ensure that prepareStackTrace() has been called. // This should populate error.__callSiteEvals. @@ -240,7 +237,7 @@ impl JsError { msg.get(scope).to_rust_string_lossy(scope), vec![], None, - Box::new(None), + None, ) }; From 705ca2908d31155aedf1055d57951c1a1b9e20b9 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 27 Dec 2021 23:45:54 +0100 Subject: [PATCH 5/9] add test --- cli/tests/integration/mod.rs | 6 ++++++ cli/tests/testdata/error_cause.ts | 1 + cli/tests/testdata/error_cause.ts.out | 11 +++++++++++ 3 files changed, 18 insertions(+) create mode 100644 cli/tests/testdata/error_cause.ts create mode 100644 cli/tests/testdata/error_cause.ts.out diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs index 8dd50b2f3269e4..0b26aaf66c985e 100644 --- a/cli/tests/integration/mod.rs +++ b/cli/tests/integration/mod.rs @@ -464,6 +464,12 @@ fn broken_stdout() { assert!(!stderr.contains("panic")); } +itest!(error_cause { + args: "run error_cause.ts", + output: "error_cause.ts.out", + exit_code: 1, +}); + itest_flaky!(cafile_url_imports { args: "run --quiet --reload --cert tls/RootCA.pem cafile_url_imports.ts", output: "cafile_url_imports.ts.out", diff --git a/cli/tests/testdata/error_cause.ts b/cli/tests/testdata/error_cause.ts new file mode 100644 index 00000000000000..a33cd15b990c86 --- /dev/null +++ b/cli/tests/testdata/error_cause.ts @@ -0,0 +1 @@ +throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); diff --git a/cli/tests/testdata/error_cause.ts.out b/cli/tests/testdata/error_cause.ts.out new file mode 100644 index 00000000000000..45194db12e697a --- /dev/null +++ b/cli/tests/testdata/error_cause.ts.out @@ -0,0 +1,11 @@ +[WILDCARD] +error: Uncaught Error: foo +throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); + ^ + at file:///[WILDCARD]/error_cause.ts:1:7 +Caused by: Uncaught Error: bar +throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); + ^ + at file:///[WILDCARD]/error_cause.ts:1:33 +Caused by: Uncaught deno +[WILDCARD] \ No newline at end of file From 329813edc957446f9e8529c9b9da9fd881e919ba Mon Sep 17 00:00:00 2001 From: crowlkats Date: Tue, 28 Dec 2021 00:16:59 +0100 Subject: [PATCH 6/9] improve test --- cli/tests/testdata/error_cause.ts | 18 +++++++++++++++++- cli/tests/testdata/error_cause.ts.out | 18 ++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cli/tests/testdata/error_cause.ts b/cli/tests/testdata/error_cause.ts index a33cd15b990c86..ad45d8ee10895c 100644 --- a/cli/tests/testdata/error_cause.ts +++ b/cli/tests/testdata/error_cause.ts @@ -1 +1,17 @@ -throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); +function a() { + throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); +} + +function b() { + a(); +} + +function c() { + b(); +} + +function d() { + c(); +} + +c(); diff --git a/cli/tests/testdata/error_cause.ts.out b/cli/tests/testdata/error_cause.ts.out index 45194db12e697a..350b71f62773dc 100644 --- a/cli/tests/testdata/error_cause.ts.out +++ b/cli/tests/testdata/error_cause.ts.out @@ -1,11 +1,17 @@ [WILDCARD] error: Uncaught Error: foo -throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); - ^ - at file:///[WILDCARD]/error_cause.ts:1:7 + throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); + ^ + at a (file:///[WILDCARD]/error_cause.ts:2:9) + at b (file:///[WILDCARD]/error_cause.ts:6:3) + at c (file:///[WILDCARD]/error_cause.ts:10:3) + at file:///[WILDCARD]/error_cause.ts:16:1 Caused by: Uncaught Error: bar -throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); - ^ - at file:///[WILDCARD]/error_cause.ts:1:33 + throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); + ^ + at a (file:///[WILDCARD]/error_cause.ts:2:35) + at b (file:///[WILDCARD]/error_cause.ts:6:3) + at c (file:///[WILDCARD]/error_cause.ts:10:3) + at file:///[WILDCARD]/error_cause.ts:16:1 Caused by: Uncaught deno [WILDCARD] \ No newline at end of file From 2cad50d3905686cf7310aad3212295420e04ddbd Mon Sep 17 00:00:00 2001 From: crowlkats Date: Tue, 28 Dec 2021 03:09:03 +0100 Subject: [PATCH 7/9] handle recursion --- cli/fmt_errors.rs | 4 ++-- cli/tests/integration/mod.rs | 6 ++++++ cli/tests/testdata/error_cause.ts | 4 ---- cli/tests/testdata/error_cause_recursive.ts | 4 ++++ cli/tests/testdata/error_cause_recursive.ts.out | 14 ++++++++++++++ core/error.rs | 16 ++++++++++++++-- 6 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 cli/tests/testdata/error_cause_recursive.ts create mode 100644 cli/tests/testdata/error_cause_recursive.ts.out diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index 5e4ce1d4f8ec4d..b4e45502696c0a 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -275,8 +275,8 @@ impl fmt::Display for PrettyJsError { let cause = self .0 .cause - .as_ref() - .map(|cause| format!("{}", PrettyJsError(*cause.clone()))); + .clone() + .map(|cause| format!("{}", PrettyJsError(*cause))); write!( f, diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs index 0b26aaf66c985e..150683749ab497 100644 --- a/cli/tests/integration/mod.rs +++ b/cli/tests/integration/mod.rs @@ -470,6 +470,12 @@ itest!(error_cause { exit_code: 1, }); +itest!(error_cause_recursive { + args: "run error_cause_recursive.ts", + output: "error_cause_recursive.ts.out", + exit_code: 1, +}); + itest_flaky!(cafile_url_imports { args: "run --quiet --reload --cert tls/RootCA.pem cafile_url_imports.ts", output: "cafile_url_imports.ts.out", diff --git a/cli/tests/testdata/error_cause.ts b/cli/tests/testdata/error_cause.ts index ad45d8ee10895c..7ebd5a48a23a82 100644 --- a/cli/tests/testdata/error_cause.ts +++ b/cli/tests/testdata/error_cause.ts @@ -10,8 +10,4 @@ function c() { b(); } -function d() { - c(); -} - c(); diff --git a/cli/tests/testdata/error_cause_recursive.ts b/cli/tests/testdata/error_cause_recursive.ts new file mode 100644 index 00000000000000..a6999b1ff06996 --- /dev/null +++ b/cli/tests/testdata/error_cause_recursive.ts @@ -0,0 +1,4 @@ +const x = new Error("foo"); +const y = new Error("bar", { cause: x }); +x.cause = y; +throw y; diff --git a/cli/tests/testdata/error_cause_recursive.ts.out b/cli/tests/testdata/error_cause_recursive.ts.out new file mode 100644 index 00000000000000..8bfda02fb377af --- /dev/null +++ b/cli/tests/testdata/error_cause_recursive.ts.out @@ -0,0 +1,14 @@ +[WILDCARD] +error: Uncaught Error: bar +const y = new Error("bar", { cause: x }); + ^ + at file:///[WILDCARD]/error_cause_recursive.ts:2:11 +Caused by: Uncaught Error: foo +const x = new Error("foo"); + ^ + at file:///[WILDCARD]/error_cause_recursive.ts:1:11 +Caused by: Uncaught Error: bar +const y = new Error("bar", { cause: x }); + ^ + at file:///[WILDCARD]/error_cause_recursive.ts:2:11 +[WILDCARD] \ No newline at end of file diff --git a/core/error.rs b/core/error.rs index 2ae4986ea20adf..dd8d95d45ebf3a 100644 --- a/core/error.rs +++ b/core/error.rs @@ -2,6 +2,7 @@ use anyhow::Error; use std::borrow::Cow; +use std::collections::HashSet; use std::fmt; use std::fmt::Debug; use std::fmt::Display; @@ -174,6 +175,14 @@ impl JsError { pub fn from_v8_exception( scope: &mut v8::HandleScope, exception: v8::Local, + ) -> Self { + Self::inner_from_v8_exception(scope, exception, Default::default()) + } + + fn inner_from_v8_exception<'a>( + scope: &'a mut v8::HandleScope, + exception: v8::Local<'a, v8::Value>, + mut seen: HashSet>, ) -> Self { // Create a new HandleScope because we're creating a lot of new local // handles below. @@ -201,10 +210,13 @@ impl JsError { "Uncaught".to_string() }; let cause = cause.and_then(|cause| { - if cause.is_undefined() { + if cause.is_undefined() || seen.contains(&cause) { None } else { - Some(Box::new(JsError::from_v8_exception(scope, cause))) + seen.insert(cause); + Some(Box::new(JsError::inner_from_v8_exception( + scope, cause, seen, + ))) } }); From 4474e6586da1e42a269de495f725d39d51610c2a Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 29 Dec 2021 16:34:29 +0100 Subject: [PATCH 8/9] fix apply source map --- cli/source_maps.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 4d13b01df7d51f..c2b95095487dbb 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -79,9 +79,14 @@ pub fn apply_source_map( } } + let cause = js_error + .cause + .clone() + .map(|cause| Box::new(apply_source_map(&*cause, getter))); + JsError { message: js_error.message.clone(), - cause: js_error.cause.clone(), + cause, source_line, script_resource_name, line_number, From 45730104341be7a94272bd94253a2c102a62899a Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 29 Dec 2021 17:04:23 +0100 Subject: [PATCH 9/9] fix test --- cli/tests/testdata/error_cause.ts.out | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/tests/testdata/error_cause.ts.out b/cli/tests/testdata/error_cause.ts.out index 350b71f62773dc..155ef656e2e89c 100644 --- a/cli/tests/testdata/error_cause.ts.out +++ b/cli/tests/testdata/error_cause.ts.out @@ -5,13 +5,13 @@ error: Uncaught Error: foo at a (file:///[WILDCARD]/error_cause.ts:2:9) at b (file:///[WILDCARD]/error_cause.ts:6:3) at c (file:///[WILDCARD]/error_cause.ts:10:3) - at file:///[WILDCARD]/error_cause.ts:16:1 + at file:///[WILDCARD]/error_cause.ts:13:1 Caused by: Uncaught Error: bar throw new Error("foo", { cause: new Error("bar", { cause: "deno" }) }); ^ at a (file:///[WILDCARD]/error_cause.ts:2:35) at b (file:///[WILDCARD]/error_cause.ts:6:3) at c (file:///[WILDCARD]/error_cause.ts:10:3) - at file:///[WILDCARD]/error_cause.ts:16:1 + at file:///[WILDCARD]/error_cause.ts:13:1 Caused by: Uncaught deno [WILDCARD] \ No newline at end of file