diff --git a/lib/execjs/graaljs_runtime.rb b/lib/execjs/graaljs_runtime.rb index 01d652d..d3cab2a 100644 --- a/lib/execjs/graaljs_runtime.rb +++ b/lib/execjs/graaljs_runtime.rb @@ -46,16 +46,18 @@ module ExecJS private + ForeignException = defined?(Polyglot::ForeignException) ? Polyglot::ForeignException : ::RuntimeError + def translate convert_js_to_ruby yield - rescue ::RuntimeError => e + rescue ForeignException => e if e.message.start_with?('SyntaxError:') error_class = ExecJS::RuntimeError else error_class = ExecJS::ProgramError end - backtrace = e.backtrace.map { |line| line.sub('(eval)', '(execjs)') } + backtrace = (e.backtrace || []).map { |line| line.sub('(eval)', '(execjs)') } raise error_class, e.message, backtrace end