我正在使用the
rubyracer和v8在rails 3 app中运行一些
javascript
如果出现任何问题,错误消息将通过电子邮件通过常见的rails 3异常通知过程发送给我.
但是,我收到的错误消息非常模糊,堆栈跟踪不会进入javascript文件本身.这是可以理解的,但是很难调试.这是一个例子:
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'
有没有办法我可以暴露javascript stacktrace,以便在抛出异常时让我可以告诉javascript里面的哪些行是borking? (至少,得到行号)
解决方法
我想你可以使用V8错误类,尝试这样做
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
说实话,我不是,如果这样可行,但试一试