Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get raw stacktrace #16

Closed
grimurd opened this issue Apr 7, 2015 · 4 comments
Closed

Get raw stacktrace #16

grimurd opened this issue Apr 7, 2015 · 4 comments

Comments

@grimurd
Copy link

grimurd commented Apr 7, 2015

I'm creating a rest api and when in development mode i also return all errors via json as well as logging it to the console. However the prettified stack trace is unreadable when it is returned as a string. Is there a way for me to get the raw stack trace before it was modified?

Example:

"message": "Cannot read property 'dataValues' of null",
"error": " �[0m�[97m�[41mError�[0m�[90m:�[0m�[37m �[0m�[97mCannot read property 'dataValues' of null�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m�[97m�[41mTypeError�[0m�[90m:�[0m�[37m �[0m�[97mCannot read property 'dataVa�[0m\ �[0m �[0m �[0m�[37mlues' of null�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[90m-�[0m �[0m�[93mloginservice.js�[0m�[90m:�[0m�[93m188�[0m�[37m �[0�[0m\ �[0m �[0m �[0m�[37mm�[37mauthenticateUser�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m �[0m�[90m/home/grimur/Documents/Repos/AuthenticationServer/src/servi�[0m\ �[0m �[0m �[0m�[37mces/loginservice.js:1�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m �[0m�[90m88:23�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[90m-�[0m �[0m�[93mq.js�[0m�[90m:�[0m�[93m794�[0m�[37m �[0m�[37m_fulf�[0m\ �[0m �[0m �[0m�[37milled�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m �[0m�[90m[AuthenticationServer]/[q]/q.js:794:54�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[90m-�[0m �[0m�[93mq.js�[0m�[90m:�[0m�[93m823�[0m�[37m �[0m�[37mself.�[0m\ �[0m �[0m �[0m�[37mpromiseDispatch.done�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m �[0m�[90m[AuthenticationServer]/[q]/q.js:823:30�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[90m-�[0m �[0m�[93mq.js�[0m�[90m:�[0m�[93m756�[0m�[37m �[0m�[37mPromi�[0m\ �[0m �[0m �[0m�[37mse.promise.promiseDispatch�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m �[0m�[90m[AuthenticationServer]/[q]/q.js:756:13�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[90m-�[0m �[0m�[93mq.js�[0m�[90m:�[0m�[93m564�[0m�[37m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m �[0m�[90m[AuthenticationServer]/[q]/q.js:564:44�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[90m-�[0m �[0m�[93mq.js�[0m�[90m:�[0m�[93m110�[0m�[37m �[0m�[37mflush�[0m\ �[0m �[0m �[0m�[37m�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m �[0m�[90m[AuthenticationServer]/[q]/q.js:110:17�[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m �[0m�[0m\ �[0m �[0m\ �[0m �[0m�[90m-�[0m �[0m�[37m�[0m�[0m\ �[0m �[0m\ �[0m"
@AriaMinaei
Copy link
Owner

How do you setup PE? Is it like require("pretty-error").start();? Or is it like pe.render(someError);?

@grimurd
Copy link
Author

grimurd commented Apr 8, 2015

require("pretty-error").start(); is how i start it. Should i do it the other way instead?

@AriaMinaei
Copy link
Owner

Well we could (and probably should) provide an api for that. But right now, if you wanna intercept an error before PE modifies it, you could do something like this:

PrettyError = require '../lib/pretty-error'
pe = new PrettyError()

prepare = Error.prepareStackTrace or (exc, frames) ->
    result = exc.toString()
    frames = frames.map (frame) -> "  at #{frame.toString()}"
    result + "\n" + frames.join "\n"

# We replace the original Error.prepareStackTrace with a custom one
Error.prepareStackTrace = (exc, trace) =>
    # Apply the modifications that were originally intended to be
    # applied on the stack trace
    stack = prepare.apply(null, arguments)
    # now we have access to the original stack trace
    console.log stack
    # and we can render the trace too
    pe.render {stack, message: exc.toString().replace /^.*: /, ''}, no

# Just a sample error to test things
a = b

I could rewrite this in JS if you prefer though.

@AriaMinaei
Copy link
Owner

Closing this issue since it's been inactive for some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants