Skip to content

Commit 086a542

Browse files
committed
fix(reporter): Enable sourcemaps for errors that without column #
1 parent 139ad83 commit 086a542

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

lib/reporter.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ var createErrorFormatter = function (basePath, emitter, SourceMapConsumer) {
4545

4646
if (file && file.sourceMap) {
4747
line = parseInt(line || '0', 10)
48-
column = parseInt(column || '0', 10)
48+
49+
column = parseInt(column, 10)
50+
51+
// When no column is given and we default to 0, it doesn't make sense to only search for smaller
52+
// or equal columns in the sourcemap, let's search for equal or greater columns.
53+
var bias = column ? SourceMapConsumer.GREATEST_LOWER_BOUND : SourceMapConsumer.LEAST_UPPER_BOUND
4954

5055
try {
5156
var original = getSourceMapConsumer(file.sourceMap)
52-
.originalPositionFor({line: line, column: column})
57+
.originalPositionFor({line: line, column: (column || 0), bias: bias})
5358

54-
return util.format('%s:%d:%d <- %s:%d:%d', path, line, column, original.source,
59+
var formattedColumn = column ? util.format(':%s', column) : ''
60+
return util.format('%s:%d%s <- %s:%d:%d', path, line, formattedColumn, original.source,
5561
original.line, original.column)
5662
} catch (e) {
5763
log.warn('SourceMap position not found for trace: %s', msg)

test/unit/reporter.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ describe('reporter', () => {
8383
}
8484
}
8585

86+
MockSourceMapConsumer.GREATEST_LOWER_BOUND = 1
87+
MockSourceMapConsumer.LEAST_UPPER_BOUND = 2
88+
8689
it('should rewrite stack traces', done => {
8790
formatError = m.createErrorFormatter('/some/base', emitter, MockSourceMapConsumer)
8891
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
@@ -98,6 +101,21 @@ describe('reporter', () => {
98101
})
99102
})
100103

104+
it('should rewrite stack traces to the first column when no column is given', done => {
105+
formatError = m.createErrorFormatter('/some/base', emitter, MockSourceMapConsumer)
106+
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
107+
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
108+
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
109+
110+
emitter.emit('file_list_modified', {served: servedFiles})
111+
112+
_.defer(() => {
113+
var ERROR = 'at http://localhost:123/base/b.js:2'
114+
expect(formatError(ERROR)).to.equal('at /some/base/b.js:2 <- /original/b.js:4:2\n')
115+
done()
116+
})
117+
})
118+
101119
it('should rewrite relative url stack traces', done => {
102120
formatError = m.createErrorFormatter('/some/base', emitter, MockSourceMapConsumer)
103121
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]

0 commit comments

Comments
 (0)