Reputation: 627
In Node, is there a way to add a line or value to the stack trace, in case of an error downstream?
I know there are LOTS of other ways to make the data available. And I am aware that the trace is not meant for value storage. But I'm wondering if this specific idea is doable (within reason).
Upvotes: 2
Views: 2087
Reputation: 627
After some further research, I don't think this is possible. Neither Javascript, V8, nor Node.js expose the stack in an editable fashion, which makes some sense. However, I did come across some useful links, worth sharing:
Upvotes: 0
Reputation: 138257
The stacktrace contains all the called functions, so that seems to be the only way, to add a function to it as an iIFE:
(function executedSomeCode() {
throw new Error("failure");
})();
Now your stacktrace contains:
...
at executedSomeCode
...
Or you just edit the stack
property of the error:
var error = new Error();
error.stack += "\nhey, whats up?";
throw error;
Upvotes: 2