Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sanjarcode opened this issue May 1, 2023 · 2 comments
Open

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

sanjarcode opened this issue May 1, 2023 · 2 comments
Assignees

Comments

@sanjarcode
Copy link
Member

sanjarcode commented May 1, 2023

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 sanjarcode self-assigned this May 1, 2023
@sanjarcode
Copy link
Member Author

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 sanjarcode changed the title CLI option to print the full stack trace, unfiltered CLI option to print the full error stack trace, unfiltered Oct 6, 2023
@sanjarcode
Copy link
Member Author

sanjarcode commented Oct 6, 2023

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:

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

@sanjarcode sanjarcode changed the title CLI option to print the full error stack trace, unfiltered CLI option control error stack - all, some, filter etc Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant