1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(test): handle scenario where --trace-ops would cause an unhandled promise rejection (#16970)

Closes #16969
This commit is contained in:
David Sherret 2022-12-06 15:58:18 -05:00 committed by GitHub
parent c03e0f3853
commit 5dbc07935d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View file

@ -227,6 +227,12 @@ mod test {
output: "test/ops_sanitizer_multiple_timeout_tests_no_trace.out",
});
itest!(trace_ops_catch_error {
args: "test -A --trace-ops test/trace_ops_caught_error/main.ts",
exit_code: 0,
output: "test/trace_ops_caught_error/main.out",
});
// TODO(@littledivy): re-enable this test, recent optimizations made output non deterministic.
// https://github.com/denoland/deno/issues/14268
//

View file

@ -0,0 +1,6 @@
Check file:///[WILDCARD]/trace_ops_caught_error/main.ts
running 1 test from ./test/trace_ops_caught_error/main.ts
handle thrown error in async function ... ok ([WILDCARD])
ok | 1 passed | 0 failed ([WILDCARD])

View file

@ -0,0 +1,12 @@
Deno.test("handle thrown error in async function", async () => {
const dirPath = Deno.makeTempDirSync();
const filePath = `${dirPath}/file.txt`;
try {
await Deno.stat(filePath);
} catch {
await Deno.writeTextFile(filePath, "");
} finally {
await Deno.remove(filePath);
await Deno.remove(dirPath);
}
});

View file

@ -187,7 +187,7 @@
// Rethrow the error
throw err;
}
handleOpCallTracing("${name}", id, promise);
promise = handleOpCallTracing("${name}", id, promise);
promise[promiseIdSymbol] = id;
return promise;
}
@ -218,10 +218,12 @@
if (opCallTracingEnabled) {
const stack = StringPrototypeSlice(new Error().stack, 6);
MapPrototypeSet(opCallTraces, promiseId, { opName, stack });
p = PromisePrototypeFinally(
return PromisePrototypeFinally(
p,
() => MapPrototypeDelete(opCallTraces, promiseId),
);
} else {
return p;
}
}