Sha256: 51f16930e1bb332f26423fbdf943a15600666d86d123fadfe85b20739977eff7

Contents?: true

Size: 1.14 KB

Versions: 58

Compression:

Stored size: 1.14 KB

Contents

# MONKEY PATCH: Got tired of having no idea what line server side errors are
#   happening on, so I patched this bit of ExecJS so it would dump the whole
#   stack trace in the log.


class ExecJS::RubyRacerRuntime::Context < ExecJS::Runtime::Context
  def eval(source, options = {})
    source = encode(source)
    return unless /\S/ =~ source
    lock do
      begin
        unbox @v8_context.eval("(#{source})")
      rescue ::V8::JSError, ::V8::Error => e
        # Make V8 errors fatal on development, log them on staging/prod
        fail e if Rails.env.development?
        do_error(e)
      end
    end # /lock
  end

  def do_error(e)
    puts "========EXECJS ERROR========"
    puts js_lines(e.backtrace)
    puts "============================"
    if e.value["name"] == "SyntaxError"
      raise ExecJS::RuntimeError, e.value.to_s
    else
      raise ExecJS::ProgramError, e.value.to_s
    end
  end

  # Get just the JS related lines of the backtrace, not the 200 levels of rails
  # abstraction
  def js_lines(backtrace)
    first_ruby_line = backtrace.find_index { |line| line.include? 'execjs' }
    return backtrace[0...first_ruby_line]
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
revelry_core-0.1.24.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.23.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.22.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.21.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.20.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.19.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.18.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.17.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.16.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.15.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.14.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.13.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.12.6 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.12.5 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.12.4 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.12.3 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.12.2 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.12.0 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.11.6 spec/dummy/config/initializers/execjs.rb
revelry_core-0.1.11.5 spec/dummy/config/initializers/execjs.rb