-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): fire 'unhandledrejection' event when using node: or npm: i…
…mports (#19235) This commit fixes emitting "unhandledrejection" event when there are "node:" or "npm:" imports. Before this commit the Node "unhandledRejection" event was emitted using a regular listener for Web "unhandledrejection" event. This listener was installed before any user listener had a chance to be installed which effectively prevent emitting "unhandledrejection" events to user code. Closes #16928
- Loading branch information
1 parent
787e1f0
commit 0bb5bbc
Showing
7 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import chalk from "npm:chalk"; | ||
|
||
console.log(chalk.red("Hello world!")); | ||
|
||
globalThis.addEventListener("unhandledrejection", (e) => { | ||
console.log("Handled the promise rejection"); | ||
e.preventDefault(); | ||
}); | ||
|
||
// deno-lint-ignore require-await | ||
(async () => { | ||
throw new Error("boom!"); | ||
})(); | ||
|
||
setTimeout(() => { | ||
console.log("Success"); | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[WILDCARD] | ||
Hello world! | ||
Handled the promise rejection | ||
Success |
21 changes: 21 additions & 0 deletions
21
cli/tests/testdata/node/unhandled_rejection_web_process.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import chalk from "npm:chalk"; | ||
import process from "node:process"; | ||
|
||
console.log(chalk.red("Hello world!")); | ||
|
||
process.on("unhandledRejection", (_e) => { | ||
console.log('process.on("unhandledRejection");'); | ||
}); | ||
|
||
globalThis.addEventListener("unhandledrejection", (_e) => { | ||
console.log('globalThis.addEventListener("unhandledrejection");'); | ||
}); | ||
|
||
// deno-lint-ignore require-await | ||
(async () => { | ||
throw new Error("boom!"); | ||
})(); | ||
|
||
setTimeout(() => { | ||
console.log("Success"); | ||
}, 1000); |
5 changes: 5 additions & 0 deletions
5
cli/tests/testdata/node/unhandled_rejection_web_process.ts.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[WILDCARD] | ||
Hello world! | ||
globalThis.addEventListener("unhandledrejection"); | ||
process.on("unhandledRejection"); | ||
Success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters