Ok, found it. You cannot reset the stack state to rebuild it again, but you
can use a custom callback function with a few lines. I thought it was more
complex but... here it is:
var formatStack = function (error, frames){
var s = error + "\n";
frames.forEach (function (frame){
s += " at " + frame + "\n";
});
return s;
};
This function is used with Error.prepareStackTrace.
When you call the function toString() of a CallSite, it automatically is
stringified like the default stack trace: Found it here:
https://github.com/joyent/node/blob/master/deps/v8/src/messages.js#L928
El jueves, 28 de noviembre de 2013 15:56:02 UTC+1, Gagle escribió:
>
> When you get the first time the stack trace of an error doing
> `error.stack`, the function `Error.prepareStackTrace` is called (if set).
> In subsequent calls to `error.stack` the function is not called, so I
> understand that the result of the previous execution is resused and
> returned.
>
> My objective is to capture the stack as string and the stack as an array
> of callsites. I can only execute one time `error.stack` to build the stack,
> but I need to build it 2 times. Is there any trick to reset the stack in
> order to rebuild it again? I'm not interested in stringify the callsites by
> myself, I want to execute the default stringify function, that's why I need
> to reset the stack, because this default stringify function cannot be
> accessed from outside (`Error.prepareStackTrace` by default is undefined).
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.