mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix(ext/fetch): Connect async error stack with user code (#13899)
This commit is contained in:
parent
f81334d5bd
commit
d2c099ce34
4 changed files with 28 additions and 2 deletions
|
@ -2517,3 +2517,10 @@ itest!(wasm_streaming_panic_test {
|
|||
output: "wasm_streaming_panic_test.js.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/denoland/deno/issues/13897.
|
||||
itest!(fetch_async_error_stack {
|
||||
args: "run --quiet -A fetch_async_error_stack.ts",
|
||||
output: "fetch_async_error_stack.ts.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
|
1
cli/tests/testdata/fetch_async_error_stack.ts
vendored
Normal file
1
cli/tests/testdata/fetch_async_error_stack.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
await fetch("https://nonexistent.deno.land/");
|
5
cli/tests/testdata/fetch_async_error_stack.ts.out
vendored
Normal file
5
cli/tests/testdata/fetch_async_error_stack.ts.out
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: Uncaught (in promise) TypeError: error sending request for url[WILDCARD]
|
||||
await fetch("https://nonexistent.deno.land/");
|
||||
^[WILDCARD]
|
||||
at async fetch (deno:[WILDCARD])
|
||||
at async file:///[WILDCARD]/fetch_async_error_stack.ts:1:1
|
|
@ -409,8 +409,13 @@
|
|||
* @param {RequestInit} init
|
||||
*/
|
||||
function fetch(input, init = {}) {
|
||||
// There is an async dispatch later that causes a stack trace disconnect.
|
||||
// We reconnect it by assigning the result of that dispatch to `opPromise`,
|
||||
// awaiting `opPromise` in an inner function also named `fetch()` and
|
||||
// returning the result from that.
|
||||
let opPromise = undefined;
|
||||
// 1.
|
||||
return new Promise((resolve, reject) => {
|
||||
const result = new Promise((resolve, reject) => {
|
||||
const prefix = "Failed to call 'fetch'";
|
||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
||||
// 2.
|
||||
|
@ -441,7 +446,7 @@
|
|||
}
|
||||
|
||||
// 12.
|
||||
PromisePrototypeCatch(
|
||||
opPromise = PromisePrototypeCatch(
|
||||
PromisePrototypeThen(
|
||||
mainFetch(request, false, requestObject.signal),
|
||||
(response) => {
|
||||
|
@ -479,6 +484,14 @@
|
|||
},
|
||||
);
|
||||
});
|
||||
if (opPromise) {
|
||||
PromisePrototypeCatch(result, () => {});
|
||||
return (async function fetch() {
|
||||
await opPromise;
|
||||
return result;
|
||||
})();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function abortFetch(request, responseObject, error) {
|
||||
|
|
Loading…
Reference in a new issue