Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiniRacer::RuntimeError does not handle multiline error messages correctly #262

Open
davidtaylorhq opened this issue Aug 30, 2022 · 1 comment
Labels

Comments

@davidtaylorhq
Copy link

begin
  MiniRacer::Context.new.eval('throw new Error("errormessage\nwith\nnewlines")')
rescue => e
  puts e.message
end

This will output

Error: errormessage

The missing lines incorrectly appear as part of e.backtrace:

JavaScript with
JavaScript newlines
JavaScript at <anonymous>:1:7
/Users/david/.rvm/gems/ruby-2.7.3/gems/mini_racer-0.6.3/lib/mini_racer.rb:228:in `eval_unsafe'
/Users/david/.rvm/gems/ruby-2.7.3/gems/mini_racer-0.6.3/lib/mini_racer.rb:228:in `block (2 levels) in eval'
...

The relevant code is:

class RuntimeError < EvalError
def initialize(message)
message, js_backtrace = message.split("\n", 2)
if js_backtrace && !js_backtrace.empty?
@js_backtrace = js_backtrace.split("\n")
@js_backtrace.map!{|f| "JavaScript #{f.strip}"}
else
@js_backtrace = nil
end
super(message)
end

@tisba tisba added the bug label Aug 30, 2022
@tisba
Copy link
Collaborator

tisba commented Aug 30, 2022

That's probably a tricky one, good find though, @davidtaylorhq and thx for reporting!

"Parsing" a JavaScript error seems to be a lot more complicated.

There is a special stack trace API (https://v8.dev/docs/stack-trace-api) in V8 that we might be able to hook into. In any case it would be super useful to have more then just the string representation in Ruby-land. Any idea if that would be possible, @SamSaffron? That might also be interesting for #129 and could could help making this way more robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants