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

fix: catch exceptions from SourceMapConsumer #1098

Merged
merged 1 commit into from
Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ var createErrorFormatter = function(basePath, emitter, SourceMapConsumer) {
column = parseInt(column || '0', 10);

var smc = new SourceMapConsumer(file.sourceMap);
var original = smc.originalPositionFor({line: line, column: column});
try {
var original = smc.originalPositionFor({line: line, column: column});

return util.format('%s:%d:%d <- %s:%d:%d', path, line, column, original.source,
return util.format('%s:%d:%d <- %s:%d:%d', path, line, column, original.source,
original.line, original.column);
} catch (e) {
log.warn('SourceMap position not found for trace: %s', msg);
// Fall back to non-source-mapped formatting.
}
}

return path + (line ? ':' + line : '') + (column ? ':' + column : '');
Expand Down
16 changes: 16 additions & 0 deletions test/unit/reporter.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ describe 'reporter', ->
constructor: (sourceMap) ->
@source = sourceMap.replace 'SOURCE MAP ', '/original/'
originalPositionFor: (position) ->
if position.line == 0
throw new TypeError('Line must be greater than or equal to 1, got 0')

source: @source
line: position.line + 2
column: position.column + 2
Expand All @@ -95,6 +98,19 @@ describe 'reporter', ->
expect(formatError ERROR).to.equal 'at /some/base/b.js:2:6 <- /original/b.js:4:8\n'
done()

it 'should fall back to non-source-map format if originalPositionFor throws', (done) ->
formatError = m.createErrorFormatter '/some/base', emitter, MockSourceMapConsumer
servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
servedFiles[0].sourceMap = 'SOURCE MAP a.js'
servedFiles[1].sourceMap = 'SOURCE MAP b.js'

emitter.emit 'file_list_modified', q(served: servedFiles)

scheduleNextTick ->
ERROR = 'at http://localhost:123/base/b.js:0:0'
expect(formatError ERROR).to.equal 'at /some/base/b.js\n'
done()

describe 'Windows', ->
formatError = null
servedFiles = null
Expand Down