google/traceur-compiler

Long stack traces

OliverJAsh opened this issue · 7 comments

I would really like to see long (async) stack traces supported in Traceur. This is currently possible with modules such as longjohn.

Having this would really help debugging with Traceur. When doing anything async, long stack traces are a must.

Can anyone talk me through where this belongs (in Traceur or in tooling) and how it might be implemented? Willing to look into this myself.

arv commented

Since Chrome supports this natively do we really need to do anything?

@arv I'm using Traceur via Node.js, so that doesn't help me much, unless I misunderstand?

What is the command you use when you are "using Traceur via Node.js"? Seems like that command just needs the longjohn require.

// traceur-runner.js
'use strict';

var traceur = require('traceur');
require('traceur-source-maps').install(traceur);
var path = require('path');

// var longjohn = require('longjohn');
// longjohn.async_trace_limit = -1;

var whitelist = [];

traceur.require.makeDefault(function (modulePath) {
    var isDependency = modulePath.indexOf('node_modules') !== -1;
    var isWhitelistedPackage = whitelist.some(function (whitelistItem) {
        return modulePath.indexOf(whitelistItem) !== -1;
    });

    return ! isDependency || isWhitelistedPackage;
});


require(path.resolve(process.cwd(), process.argv[2]));

And then:

node traceur-runner.js main.js

I apply the traceur-source-maps package which maps error stack traces back to source (this is not done by default, see #1433).

If I then try to apply longjohn after this (commented out), it undoes the work done by traceur-source-maps, leaving me with long stack traces but mapped to the compiled ES5 code, not the source ES6.

My goal is to have source map resolved and long stack traces.

Take a look at src/node/System.js and pass {sourceMaps: true} as the options argument to makeDefault.

Was #1433 was supposedly fixed by #1475?

I just tested it here:

https://gist.github.com/OliverJAsh/0a9fb23dc3ea9bc7914c

When I run the Node script through Traceur, my error call stack is still incorrect:

/Users/Oliver/Development/tmp/traceur-longjohn/main.js:10
    throw new Error('foo');
          ^
Error: foo
    at foo [as _onTimeout] (/Users/Oliver/Development/tmp/traceur-longjohn/main.js:10:11)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

The sourceMaps option seems to make no difference here.