7

我正在使用 therubyracer 和 v8 在 rails 3 应用程序中运行一些 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 中的哪一行正在运行?(至少,获取行号)

4

1 回答 1

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

老实说,我不认为这会奏效,但试一试

于 2015-08-04T11:29:45.070 回答