Lamp
Lamp4w ago

"Uncaught (in promise)" EVEN THOUGH IT WAS CAUGHT

This is bs.
No description
2 Replies
Lamp
LampOP4w ago
it's caused by this thing to deduplicate calls to a function
No description
Lamp
LampOP4w ago
i think there is a bug never had issue with this on nodejs nothing is ever uncaught there is one or more code paths with an error catch at the end calling the same promise need to figure out how to reproduce well I reproduced it and it's not deno issue cause it happens in nodejs too
var tasks = new Map();
async function runTaskDeduplicated(taskid) {
var run = tasks.get(taskid);
if (!run) {
run = asyncTaskThatFails(taskid);
run.finally(() => {
tasks.delete(taskid);
});
}
return await run;
}

async function asyncTaskThatFails(taskid) {
//await new Promise(r => setTimeout(r, 3000));
throw new Error("AAAAA");
}

try {
await runTaskDeduplicated("12345");
} catch (error) {
console.error("The error was caught:", error);
}
var tasks = new Map();
async function runTaskDeduplicated(taskid) {
var run = tasks.get(taskid);
if (!run) {
run = asyncTaskThatFails(taskid);
run.finally(() => {
tasks.delete(taskid);
});
}
return await run;
}

async function asyncTaskThatFails(taskid) {
//await new Promise(r => setTimeout(r, 3000));
throw new Error("AAAAA");
}

try {
await runTaskDeduplicated("12345");
} catch (error) {
console.error("The error was caught:", error);
}
I don't understand what's wrong
> deno run .\bug.js
The error was caught: Error: AAAAA
at asyncTaskThatFails (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:15:8)
at runTaskDeduplicated (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:5:9)
at file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:19:8
error: Uncaught (in promise) Error: AAAAA
throw new Error("AAAAA");
^
at asyncTaskThatFails (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:15:8)
at runTaskDeduplicated (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:5:9)
at file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:19:8
> deno run .\bug.js
The error was caught: Error: AAAAA
at asyncTaskThatFails (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:15:8)
at runTaskDeduplicated (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:5:9)
at file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:19:8
error: Uncaught (in promise) Error: AAAAA
throw new Error("AAAAA");
^
at asyncTaskThatFails (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:15:8)
at runTaskDeduplicated (file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:5:9)
at file:///C:/Users/me/Desktop/ytdls3-deno/bug.js:19:8
caught but not caught???
var run = Promise.reject("foobar");
//run.then(()=>{});

try {
await run;
console.log("no caught");
} catch (error) {
console.error("caught:", error);
}
var run = Promise.reject("foobar");
//run.then(()=>{});

try {
await run;
console.log("no caught");
} catch (error) {
console.error("caught:", error);
}
works as expected
> deno run .\bug2.js
caught: foobar
> deno run .\bug2.js
caught: foobar
but if you uncomment .then(), this happens.
caught: foobar
error: Uncaught (in promise) "foobar"
caught: foobar
error: Uncaught (in promise) "foobar"
what the hell?? xD

Did you find this page helpful?