mini_racer: Meaningful errors with inlined sourcemaps

Hi

I’m using webpack to compile a server side js bundle with inlined sourcemaps, used to render server side views. Everything’s going well except errors. The stack trace given back is reasonable, eg:

ExecJS::ProgramError - ReferenceError: func is not defined:
  Widget.vtree (eval at <anonymous> ((execjs):357:in `'
  Widget.render (eval at <anonymous> ((execjs):391:in `'
  Object.render (eval at <anonymous> ((execjs):1379:in `'

This error is okay, i can follow it from the entry point but I don’t get a strong gauge on which line in which file, which would be available in chrome, for example.

Is there a way to do that, to get more specific information about which line and which file is causing the exception?

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Source maps are working well for me now. here’s what i did:

ctx = MiniRacer::Context.new
ctx.eval(my_script_string, filename: "my_script_string.js") # important!
ctx.attach('readSourceMap', proc { |source_filename| File.read("#{source_filename].map") })

now, somewhere in your js:

if (process.env.NODE_ENV === "production") {
  require("source-map-support").install({
    retrieveSourceMap: (filename) => {
      return {
        url: filename,
        // @ts-ignore
        map: readSourceMap(filename)
      };
    }
  });
}

This works with a fairly advanced webpack setup flawlessly.

-duh- okay, sorry that makes perfect sense. The require is translated by webpack and the npm package will patch Error.prototype (or something like that).

So technically no webpack is required and you could simply “eval” source-map-support, attach readSourceMap and then eval your script - at least if I understand this correctly.

V8 does not implement any source map logic, the logic all exists in the inspector which is a javascript package from what I can tell.

On Fri, Jun 2, 2017 at 10:54 PM, siassaj notifications@github.com wrote:

@SamSaffron https://github.com/samsaffron your comment, it seems to imply that V8 isn’t going to change how it reports it’s errors, and that the consumer (in this case mini_racer) would have to scan the sourcemap and construct a meaningful view of the error itself from the data returned by V8.

Is that a fair assessment?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/discourse/mini_racer/issues/58#issuecomment-305946071, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAUXQd9Zxx1uyOkXusObM9uoUdHNXKhks5sAMrVgaJpZM4Nup14 .

@ignisf tried to make that work but it was futile