deno: Errors in dynamic imports are not properly caught
Runtime
debian 10
deno 1.6.2
v8 8.8.278.2
typescript 4.1.3
//a.ts
import("./b.ts").catch(e=>{
console.log("caught import b.ts error")
console.error(e)
})
import("./c.ts").catch(e=>{
console.log("caught import c.ts error")
console.error(e)
})
setInterval(function () {
import("./c.ts").catch((e) => {
console.log("caught interval import c.ts error");
console.error(e);
});
}, 1e3);
//b.ts
// @ts-ignore
import "./b1.ts";
export default () => "error";
//c.ts
// @ts-ignore
await import("./c1.ts");
export default () => "error";
create those files and then run deno run -A a.ts, you will get log like below:
caught import b.ts error
TypeError: Cannot resolve module "file://yourdir/b1.ts" from "file://yourdir/b.ts".
at file://yourdir/b.ts:3:0
caught import c.ts error
TypeError: Cannot resolve module "file://yourdir/c1.ts".
error: Uncaught TypeError: Cannot resolve module "file://yourdir/c1.ts".
import('./c.ts') first error is caught, but then second import is not caught and it make my program exit
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 19 (9 by maintainers)
Commits related to this issue
- fix(cli): make dynamic import errors catchable Fixes #6259 — committed to kitsonk/deno by kitsonk 4 years ago
- fix(cli): make dynamic import errors catchable Fixes #6259 — committed to kitsonk/deno by kitsonk 4 years ago
- fix(cli): make dynamic import errors catchable (#8750) Fixes #6259 — committed to denoland/deno by kitsonk 4 years ago
- fix(cli): make dynamic import errors catchable (#8750) Fixes #6259 — committed to lucacasonato/deno by kitsonk 4 years ago
- fix(core): Make dynamic import async errors catchable (#9505) Fixes #6259 — committed to denoland/deno by nayeemrmn 3 years ago
- fix(core): Make dynamic import async errors catchable (#9505) Fixes #6259 — committed to denoland/deno by nayeemrmn 3 years ago
- fix(core): preserve syntax error locations in dynamic imports (#18664) Fixes #6259. Adds the location for v8 syntax errors to the message (`message += " at {location}"`) when rethrowing them for ... — committed to denoland/deno by nayeemrmn a year ago
- fix(core): preserve syntax error locations in dynamic imports (#18664) Fixes #6259. Adds the location for v8 syntax errors to the message (`message += " at {location}"`) when rethrowing them for ... — committed to denoland/deno by nayeemrmn a year ago
Smaller repro:
It occurs because this line: https://github.com/denoland/deno/blob/5873adeb5e6ec2113eeb5adc964b7ce129d4905d/core/runtime.rs#L814 attempts to remove the promise from the list of exceptions before it is ever added by this line: https://github.com/denoland/deno/blob/5873adeb5e6ec2113eeb5adc964b7ce129d4905d/core/bindings.rs#L284-L286 so it is never removed. For modules with “truly” async top levels, the first one is run after the promise is returned while the second is run after it rejects. Fix coming.
https://github.com/caramboleyo/deno-topfen
Some of the fixes that are out there may impact this @bartlomieju.