You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just saw this question where a user was confused about a stack trace they got when using puppeteer:
Unhandled Rejection at: Promise Promise {
<rejected> Error: Navigation Timeout Exceeded: 30000ms exceeded
at Promise.then (C:\...\pupet test\node_modules\pupp
eteer\lib\NavigatorWatcher.js:71:21)
at <anonymous> } reason: Error: Navigation Timeout Exceeded: 30000ms exceede
d
at Promise.then (C:\...\pupet test\node_modules\pupp
eteer\lib\NavigatorWatcher.js:71:21)
at <anonymous>
The point is, the first few stack frames are irrelevant to the user. If the first stack frame showed the part in their code that caused the error it would have been a lot more useful.
I'm wondering if we can improve the debugging experience of users by giving them "Just My Code"
Just My Code
Node could expose a "Just My Code" exception mode similar to the way stacks work in the Chrome devtools. Running Node with the flag would hide any frames from node_modules folder.
Seems pretty well suited to the user-land, no? Just use a custom Error.prepareStackTrace that filters out Node.js core modules & node_modules code. There are some edge cases but I don't think that's a good reason to make it be a part of the core.
One argument in favor is that only core can disambiguate stack frames with 100% certainty.
vm.runInThisContext('throw new TypeError()', {filename:'vm.js'}) throws an exception that looks like it comes from the vm module, but doesn't, and there's really no way for a user land hook to tell.
That said, I don't necessarily think hiding stack frames is a good idea. I can quickly see that turning into a bigger hindrance than a help, with people filing bug reports with unhelpful stack traces. Getting a good bug report is already more the exception than the norm, in this day and age.
Reacted by Benjamin Gruenbaum, mary marchini, MBetters, Denys Otrishko and John Shine
If it can be done reasonably well I think this would be excellent to have but I definitely share @bnoordhuis' concern around it. It wouldn't hurt to have some non-committal experimentation around it.
Problem with just different Coloring is when you use SDKs which transfer the flow of control a lot.
I use the aws-sdk a lot and the stack traces there are not useful because it is filled with the stack of the internal function calls, hiding frames from node_modules option will help a lot in this case.
Just realize that we have a default Error.stackTraceLimit = 10, so unless users set this to a higher value, many of our internal stack frames are probably not going to be visible to them anyway if their code throws in a sufficiently deep call stack.
Another idea would be to exclude all the stack frames up to the first frame of user code (on master it's usually Module._compile and 8 frames below)
Reacted by Benjamin Gruenbaum, techsin, John Shine and Chris Deacy
This is partially fixed since a while. Using console.log or util.inspect on errors marks Node.js stack frames grey and adds an underscore to node_modules names. We could go ahead and add a color to node_modules frames but not everyone wanted that. Should this stay open or shall we consider it as solved?
@joyeecheungError.stackTraceLimit doesn't solve the issue, it just changes the number of lines it prints.
For example in the following stack, only two lines (related to file prepareServer) were related to files I developed (followed by <===). The others for me are noise
Error
at buildAdministrationsObject (/home/joao/dev/geoptapi/prepareServer.js:350:11) <===
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:3638:28
at replenish (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:443:21)
at iterateeCallback (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:427:21)
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:324:20
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:3643:17
at /home/joao/dev/geoptapi/prepareServer.js:158:7 <===
at wrapper (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:271:20)
at iterateeCallback (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:424:28)
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:324:20
If I change Error.stackTraceLimit = 6 for example I will miss my second line.
I just want to filter out lines including node_modules
Activity
apapirovski commentedon May 3, 2018
Seems pretty well suited to the user-land, no? Just use a custom
Error.prepareStackTracethat filters out Node.js core modules & node_modules code. There are some edge cases but I don't think that's a good reason to make it be a part of the core.(Can also do all kinds of other neat things with the API https://github.com/v8/v8/wiki/Stack-Trace-API)
bnoordhuis commentedon May 8, 2018
One argument in favor is that only core can disambiguate stack frames with 100% certainty.
vm.runInThisContext('throw new TypeError()', {filename:'vm.js'})throws an exception that looks like it comes from the vm module, but doesn't, and there's really no way for a user land hook to tell.That said, I don't necessarily think hiding stack frames is a good idea. I can quickly see that turning into a bigger hindrance than a help, with people filing bug reports with unhelpful stack traces. Getting a good bug report is already more the exception than the norm, in this day and age.
techsin commentedon Oct 5, 2018
maybe a plugin that make colors of files in node_modules gray and less contrast so you can see what file are yours
jasnell commentedon Oct 5, 2018
If it can be done reasonably well I think this would be excellent to have but I definitely share @bnoordhuis' concern around it. It wouldn't hurt to have some non-committal experimentation around it.
techsin commentedon Oct 5, 2018
so what im saying wont hide it, but only visually color it differently in terminal.
techsin commentedon Oct 5, 2018
i created a simple script that accomplishes what i was thinking....
I simply put it in main app.js file
then in one of my routes of app
throw new Error('test');result ....
https://github.com/v8/v8/wiki/Stack-Trace-API
AyushG3112 commentedon Oct 6, 2018
Problem with just different Coloring is when you use SDKs which transfer the flow of control a lot.
I use the
aws-sdka lot and the stack traces there are not useful because it is filled with the stack of the internal function calls, hiding frames fromnode_modulesoption will help a lot in this case.techsin commentedon Oct 6, 2018
didn't explain how coloring won't help sdk traces which live in node_modules...
joyeecheung commentedon Nov 27, 2018
Just realize that we have a default
Error.stackTraceLimit = 10, so unless users set this to a higher value, many of our internal stack frames are probably not going to be visible to them anyway if their code throws in a sufficiently deep call stack.Another idea would be to exclude all the stack frames up to the first frame of user code (on master it's usually
Module._compileand 8 frames below)BridgeAR commentedon Jan 4, 2020
This is partially fixed since a while. Using
console.logorutil.inspecton errors marks Node.js stack frames grey and adds an underscore tonode_modulesnames. We could go ahead and add a color to node_modules frames but not everyone wanted that. Should this stay open or shall we consider it as solved?jasnell commentedon Jun 19, 2020
I'd say let's consider it solved. If someone wishes to make further enhancements, a PR with a concrete proposal would be ideal. Closing
jfoclpf commentedon Oct 6, 2021
@joyeecheung
Error.stackTraceLimitdoesn't solve the issue, it just changes the number of lines it prints.For example in the following stack, only two lines (related to file
prepareServer) were related to files I developed (followed by<===). The others for me are noiseIf I change
Error.stackTraceLimit = 6for example I will miss my second line.I just want to filter out lines including
node_modulesjfoclpf commentedon Oct 6, 2021
Came up with this solution that strips out any line with
/node_modules/or\node_modules\Now as I wanted :)
what do you think @jasnell ?
taljacob2 commentedon Sep 22, 2023
I edited @techsin comment with the following: