question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:

  1. Run a test with an unhandled rejection, for example:
test("foo", () => {
  Promise.reject(new Error());
  expect(1).toBe(1);
});
  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:open
  • Created 3 years ago
  • Reactions:49
  • Comments:27 (7 by maintainers)

github_iconTop GitHub Comments

15reactions
justsmlcommented, Feb 17, 2021

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.

image

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?

14reactions
LvChengbincommented, Apr 24, 2021

Currently, you can just use NODE_OPTIONS=--unhandled-rejections=warn yarn test to resolve this problem.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found