1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix: add error cause in recursive cause tail (#16306)

This commit is contained in:
Cre3per 2022-10-16 21:16:46 +02:00 committed by GitHub
parent 5252ff5dbd
commit cf1be5e76f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View file

@ -3374,6 +3374,12 @@ itest!(error_cause {
exit_code: 1,
});
itest!(error_cause_recursive_tail {
args: "run error_cause_recursive_tail.ts",
output: "error_cause_recursive_tail.ts.out",
exit_code: 1,
});
itest!(error_cause_recursive {
args: "run run/error_cause_recursive.ts",
output: "run/error_cause_recursive.ts.out",

View file

@ -0,0 +1,5 @@
const foo = new Error("foo");
const bar = new Error("bar", { cause: foo });
const baz = new Error("baz", { cause: bar });
foo.cause = bar;
throw baz;

View file

@ -0,0 +1,12 @@
[WILDCARD]
error: Uncaught Error: baz
const baz = new Error("baz", { cause: bar });
^
at file:///[WILDCARD]/error_cause_recursive_tail.ts:3:13
Caused by: Error: bar
at file:///[WILDCARD]/error_cause_recursive_tail.ts:2:13
Caused by: Error: foo
at file:///[WILDCARD]/error_cause_recursive_tail.ts:1:13
Caused by: Error: bar
at file:///[WILDCARD]/error_cause_recursive_tail.ts:2:13
[WILDCARD]

View file

@ -209,7 +209,7 @@ impl JsError {
fn inner_from_v8_exception<'a>(
scope: &'a mut v8::HandleScope,
exception: v8::Local<'a, v8::Value>,
mut seen: HashSet<v8::Local<'a, v8::Value>>,
mut seen: HashSet<v8::Local<'a, v8::Object>>,
) -> Self {
// Create a new HandleScope because we're creating a lot of new local
// handles below.
@ -254,10 +254,10 @@ impl JsError {
}
});
let cause = cause.and_then(|cause| {
if cause.is_undefined() || seen.contains(&cause) {
if cause.is_undefined() || seen.contains(&exception) {
None
} else {
seen.insert(cause);
seen.insert(exception);
Some(Box::new(JsError::inner_from_v8_exception(
scope, cause, seen,
)))