sourcemapped-stacktrace icon indicating copy to clipboard operation
sourcemapped-stacktrace copied to clipboard

mapStackTrace fails to sourcemap my coffeescript files in Chrome

Open dgoldstein0 opened this issue 9 years ago • 6 comments

Background: I'm using sourcemapped-stacktrace with jasmine 2.3.4 as suggested by https://gist.github.com/guncha/f45ceef6d483c384290a. After getting this set up, I was surprised to see that my coffeescript source lines - which are the ones I really care about - weren't being mapped at all. I wrote a simple example jasmine test to illustrate.

Here's a sample stack trace where i reproduced the problem:

"Error: Expected 5 to equal 4.
    at stack (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1201:27)
    at buildExpectationResult (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1176:20)
    at Spec.expectationResultFactory (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:467:24)
    at Spec.addExpectationResult (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:261:38)
    at Expectation.addExpectationResult (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:428:29)
    at Expectation.toEqual (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1143:18)
    at https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/tests/jasmine_tests/example-vflDEVHASH.js:5:24
    at Object.arguments.(anonymous function) (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine-promises-vflDEVHASH.js:71:47)
    at attemptAsync (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1501:32)
    at QueueRunner.run (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1456:17)"

In particular, the line at https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/tests/jasmine_tests/example-vflDEVHASH.js:5:24 should be sourcemapped to a line in /static/coffee/tests/jasmine_tests/example.coffee. After debugging, I found that the regex chosen for Chrome (https://github.com/novocaine/sourcemapped-stacktrace/blob/d29fa9826311fd99183edd2cde302fe7809a5919/sourcemapped-stacktrace.js#L42) does not match this stack line.

example.coffee:

define [], ->
  describe "example", ->
    it "tries to test something", ->
      expect(5).toEqual(4)

This repros for essentially all coffeescript files I've tried. It's worth noting, for those unfamiliar with coffeescript, that coffeescript tends to only use anonymous functions - not sure if that has something to do with it or not.

dgoldstein0 avatar Jul 09 '16 05:07 dgoldstein0

Hi,

Sorry to hear that it is not working for you.

The smst demo includes coffeescript: http://novocaine.github.io/sourcemapped-stacktrace-demo/public_html/smst.html

I'm not sure the regex itself is the problem, as this works for me:

x = "    at stack (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1201:27)"
regex = /^ +at.+\((.*):([0-9]+):([0-9]+)/;
x.match(regex)
["    at stack (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1201:27", "https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js", "1201", "27"]

Perhaps you could try to work out what is working correctly in the demo's coffeescript processing that isn't working for you?

Or put a jsfiddle or similar up reproducing the issue? Not sure how else I can help debug from afar.

novocaine avatar Jul 09 '16 08:07 novocaine

That particular stack line - for the coffeescript file - has no parentheses in it. I don't know how chrome decides to format it's stacks, but that's what it gave me.

I guess I should check what version of chrome I'm using.

On Sat, Jul 9, 2016, 1:18 AM James Salter [email protected] wrote:

Hi,

Sorry to hear that it is not working for you.

The smst demo includes coffeescript: http://novocaine.github.io/sourcemapped-stacktrace-demo/public_html/smst.html

I'm not sure the regex itself is the problem, as this works for me:

x = " at stack (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1201:27)" regex = /^ +at.+((.*):([0-9]+):([0-9]+)/; x.match(regex) [" at stack (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1201:27", "https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js", "1201", "27"]

Perhaps you could try to work out what is working correctly in the demo's coffeescript processing that isn't working for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/novocaine/sourcemapped-stacktrace/issues/16#issuecomment-231522721, or mute the thread https://github.com/notifications/unsubscribe/ABBnd3P5__kg616tN8A-_e8kr3oC4x2Xks5qT1lpgaJpZM4JIi3p .

dgoldstein0 avatar Jul 09 '16 21:07 dgoldstein0

oh I see, your problem is with

at https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/tests/jasmine_tests/example-vfl
DEVHASH.js:5:24

but the other lines are fine. Sorry I didn't grok that. Okay, I guess we need to adjust the line parser. Do you get the same issue in firefox? Are you able to provide me with example-vflDEVHASH.js?

novocaine avatar Jul 10 '16 16:07 novocaine

Right

On Sun, Jul 10, 2016, 9:33 AM James Salter [email protected] wrote:

oh I see, your problem is with

at https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/tests/jasmine_tests/example-vfl DEVHASH.js:5:24

but the other lines are fine. Okay, I guess we need to adjust the line parser.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/novocaine/sourcemapped-stacktrace/issues/16#issuecomment-231597854, or mute the thread https://github.com/notifications/unsubscribe/ABBnd8nsCJy2xnUZKANsW9UT74pGLmLJks5qUR7ggaJpZM4JIi3p .

dgoldstein0 avatar Jul 10 '16 19:07 dgoldstein0

Hey, sorry but I can't effectively fix this until you post the js source or the trace in firefox.

novocaine avatar Jul 25 '16 20:07 novocaine

I actually didn't keep that original test case around, so here's a new one that should repro it:

/static/coffee/modules/example.test.coffee:

define [], ->
  describe "example", ->
    it "fails", ->
      foo.bar

compiles to /static/javascript/compiled/modules/example.test.js:

// Generated by CoffeeScript 1.10.0
(function() {
  define([], function() {
    return describe("example", function() {
      return it("fails", function() {
        return foo.bar;
      });
    });
  });

}).call(this);

//# sourceMappingURL=example.test.js.map

sourcemap /static/javascript/compiled/modules/example.test.js.map:

{
  "version": 3,
  "file": "example.test.js",
  "sourceRoot": "../../../coffee",
  "sources": [
    "modules/example.test.coffee"
  ],
  "names": [],
  "mappings": ";AAAA;EAAA,MAAA,CAAO,EAAP,EAAW,SAAA;WACT,QAAA,CAAS,SAAT,EAAoB,SAAA;aAClB,EAAA,CAAG,OAAH,EAAY,SAAA;eACV,GAAG,CAAC;MADM,CAAZ;IADkB,CAApB;EADS,CAAX;AAAA"
}

When I run this under jasmine in Chrome, I get this stack trace:

    ReferenceError: foo is not defined
    at https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/modules/example.test.js:6:16
    at Object.arguments.(anonymous function) (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine-promises-vflDEVHASH.js:71:47)
    at attemptAsync (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1501:32)
    at QueueRunner.run (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1456:17)
    at QueueRunner.execute (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1449:14)
    at Spec.queueRunnerFactory (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:504:41)
    at Spec.execute (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:283:14)
    at Object.fn (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1934:30)
    at attemptAsync (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1501:32)
    at QueueRunner.run (https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1456:17)"

And with Firefox I end up with a much longer stack trace with weirder issues:

@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/modules/example.test.js:6:9
patchFunction/obj[slot]/arguments[fnArgIndex]@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine-promises-vflDEVHASH.js:71:47
attemptAsync@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1501:17
QueueRunner.prototype.run@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1456:17
QueueRunner.prototype.execute@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1449:9
Env/queueRunnerFactory@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:504:13
Spec.prototype.execute@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:283:1
executeNode/<.fn@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1934:25
attemptAsync@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1501:17
QueueRunner.prototype.run@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1456:17
QueueRunner.prototype.execute@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1449:9
Env/queueRunnerFactory@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:504:13
executeNode/<.fn@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1918:1
attemptAsync@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1501:17
QueueRunner.prototype.run@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1456:17
QueueRunner.prototype.execute@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1449:9
Env/queueRunnerFactory@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:504:13
TreeProcessor/this.execute@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:1808:1
Env/this.execute@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/jasmine-vflDEVHASH.js:547:13
window.onload@https://cf-servervm2.dev.corp.dropboxstatic.com/static/javascript/compiled/external/jasmine/boot-vflDEVHASH.js:58:9
... (code loading from requirejs down this way, omitted for brevity)

in both cases the first line is not properly handled.

dgoldstein0 avatar Aug 17 '16 10:08 dgoldstein0