Stack trace from javascript error from therubyracer / v8 in rails 3
Asked Answered
P

1

7

I am running some javascript inside a rails 3 app using therubyracer and v8

If anything goes wrong, the error message gets sent to me via email through the usual rails 3 exception notification process.

However, the error message I get back is pretty vague and the stack trace doesn't go into the javascript file itself. This is understandable, but makes it pretty hard to debug. Here's an example:

V8::JSError: Cannot read property '0' of undefined
backtrace:

lib/libraryname.rb:32:in `function_that_calls_v8'
lib/libraryname.rb:18:in `fetch_and_update'
app/models/listing.rb:34:in `fetch'

Is there a way I can expose the javascript stacktrace so that when an exception is thrown so that I can tell what line inside the javascript is borking? (at the very least, get the line number)

Pasteup answered 8/11, 2012 at 18:33 Comment(0)
F
0

I think you can use the V8 error class, try doing this

begin
  #normal V8 code


rescue V8::Error => error
  error.value #the JavaScript value passed to the `throw` statement
  error.cause #the underlying error (if any) that triggered this error to be raised
  error.javascript_backtrace #the complete JavaScript stack at the point this error was thrown
  #use these values and send them to the exception system (however that happenS)
end

To be honest, I'm not if that will work but give it a try

Footpoundsecond answered 4/8, 2015 at 11:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.