我正在使用therubyracer和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堆栈跟踪,以便在抛出异常时让我可以告诉javascript里面的哪一行是borking? (至少,得到行号)
答案 0 :(得分:0)
我认为您可以使用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
说实话,我不是,如果那会起作用但是试一试