Do not filter out stack trace for unhandled rejections
See original GitHub issueš Bug Report
In strict unhandled rejections mode (https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode), the stack trace of unhandled rejection is not displayed in the console. This mode is default in Node.js 15.
To Reproduce
Steps to reproduce the behavior:
- Run a test with an unhandled rejection, for example:
test("foo", () => {
Promise.reject(new Error());
expect(1).toBe(1);
});
- The output is:
RUNS ./index.test.js
node:internal/process/promises:218
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error".] {
code: 'ERR_UNHANDLED_REJECTION'
}
Expected behavior
The stack trace is displayed in the console.
Link to repl or repo (highly encouraged)
https://github.com/vkrol/jest-unhandled-rejection-stack-trace
envinfo
System:
OS: Windows 10 10.0.19042
CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
Binaries:
Node: 15.1.0 - ~\scoop\apps\nodejs\current\node.EXE
Yarn: 1.22.5 - ~\scoop\apps\yarn\current\Yarn\bin\yarn.CMD
npm: 7.0.8 - ~\scoop\apps\nodejs\current\npm.CMD
npmPackages:
jest: 26.6.3 => 26.6.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:49
- Comments:27 (7 by maintainers)
Top Results From Across the Web
RethinkDB Unhandled Rejection No stack trace
You would need to include the database: 'databasename' field in the config object and pass the config object into run, otherwise you couldĀ ......
Read more >How to prevent logging unhandled rejections from 3rd-party ...
In client-side Javascript, we load a script that does logging for analytics ... than we could at least get a stack trace out...
Read more >Tracking Unhandled Promise Rejections - TrackJS
If you get in the habit of rejecting your promises with Error objects instead of strings, TrackJS can also give you the stack...
Read more >Best Practices for Node.js Error-handling - Toptal
My answer to them is āNo, Node.js is not bad at all. ... information about errors like StackTrace, which most developers depend on...
Read more >Collecting Browser Errors - Datadog Docs
The error message and stack trace are included when available. ... handled promise rejections, and other errors not tracked automatically by the RUM...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is such a frustrating default behavior. Usually I can quickly figure out the location of the error, but today Iāve been working on the wrong area of my app.
Turns out the bug wasnāt caused by my code changes, but an upgraded dependency in unrelated codeā¦
I had to use VS Code debugger to trap the error. It was pretty frustrating to find all the line number details Iād expect were there. They were simply dropped by node+jestās output.
Is there a way to let users know the risk of using
NODE_OPTIONS="--unhandled-rejections=strict"
?Or is there a node.js option to make the crash behavior less user-hostile?
Currently, you can just use
NODE_OPTIONS=--unhandled-rejections=warn yarn test
to resolve this problem.