sanjar-notes / nodejs

Node, Express and helper app libs
https://sanjar-notes.github.io/nodejs/
GNU General Public License v3.0
0 stars 0 forks source link

CLI option control error stack - all, some, filter etc #7

Open sanjarcode opened 1 year ago

sanjarcode commented 1 year ago

Node.js is not printing the full error stack trace, only traces inside of node_modules are being print, and so I cannot see my app code. Is there a CLI option in Node.js to print the whole stack trace, unfiltered — Sanjar

By default Node.js limits the number of stack trace lines that are printed to the console. However, you can increase the stack trace limit by setting the NODE_OPTIONS environment variable when running your Node.js application.

To print the full stack trace, you can set --trace-warnings and --stack-trace-limit=100000 flags in NODE_OPTIONS environment variable. — ChatGPT

Example

NODE_OPTIONS='--trace-warnings --stack-trace-limit=100000' node app.js

Note: this may impact performance. Use with caution

sanjarcode commented 1 year ago

Explore more:

  1. How to force traces to have relative path based on project path, instead of absolute paths
  2. Exclude node_modules traces, or limit them to a small number
sanjarcode commented 1 year ago

me on StackOverflow

## Solution Use the CLI option 1. Direct `node` - `NODE_OPTIONS='--stack-trace-limit=0' node myApp.js` 2. npm script - `NODE_OPTIONS='--stack-trace-limit=0' npm myStart` Optional: you change the value (zero here). Negative values print less, and positive prints more. For example - setting to 10 will print only the first 10 `node_modules` errors. Source: https://nodejs.org/api/cli.html ## Override default stack size (the actual problem) Node limts the default error stack size (number of errors). To print all errors, run the following: ```sh NODE_OPTIONS='--trace-warnings --stack-trace-limit=100000' node app.js ``` Optional: You can replace 100000 to set the limit.

has some issues, will fix