AriaMinaei / pretty-error

See node.js errors with less clutter
MIT License
1.52k stars 49 forks source link

Document .stop() / a way to obtain unmodified stack traces #53

Open apopescu-im opened 6 years ago

apopescu-im commented 6 years ago

I had an issue where I needed to obtain an un-modified stack trace for another package to parse information out of. In the end I solved it as:

pe.stop();
const stack = (new Error()).stack;
pe.start();

It took some digging and intuition to find .stop() so it would be helpful if this was mentioned in the readme.

The reason I didn't individually format errors instead of .start() is that I have many places where errors may be output, but only one where I need this raw trace.

Question: Is the original .stack stored anywhere? I think it would be great to be able to access it, as well as the ParsedError (to eliminate the need for other parsing packages since the message is parsed once here anyway)

AriaMinaei commented 6 years ago

It took some digging and intuition to find .stop() so it would be helpful if this was mentioned in the readme.

Thank for mentioning this. You're welcome to submit a PR for this :-)

Question: Is the original .stack stored anywhere? I think it would be great to be able to access it, as well as the ParsedError (to eliminate the need for other parsing packages since the message is parsed once here anyway)

No it's not, but now that you mention it, we should preserve the original stack trace. The relevant code is here: https://github.com/AriaMinaei/pretty-error/blob/ba54889c642f3e2a56eb5e657c09c6cac6e4712e/src/PrettyError.coffee#L53

Again, PRs welcome :)