Reputation: 14318
Is it possible to get the entire stack trace in Node? The following script should print 100 items, but only prints 10. Note, it does work in Chrome, just not in Node. (To run the snippet below and see results, you'll actually need to open the browser's dev tools.)
function trace(depth = 100) {
if (!depth) {
console.trace();
} else {
trace(depth - 1);
}
}
trace();
I've also tried the new Error().stack
method, but this prints the same limited number of lines. Unlike stack.trace()
this method also only displays 10 items in Chrome.
function trace(depth = 100) {
if (!depth) {
console.info(new Error().stack);
} else {
trace(depth - 1);
}
}
trace();
The debugger knows the entire stack trace, not to mention the JS engine itself needs to be able to walk the stack for closures, so there must be a way.
Upvotes: 2
Views: 2253
Reputation: 7241
In your code, you need to declare:
Error.stackTraceLimit = Infinity;
This works for both methods in the OP.
Upvotes: 10