Skip to content

Commit

Permalink
feat(client): log global error stack trace
Browse files Browse the repository at this point in the history
Closes #2812
  • Loading branch information
briandipalma authored and dignifiedquire committed Aug 22, 2017
1 parent fafa700 commit 523d608
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,36 @@ var Karma = function (socket, iframe, opener, navigator, location) {
navigateContextTo('about:blank')
}

function getLocation (url, lineno, colno) {
var location = ''

if (url !== undefined) {
location += url
}

if (lineno !== undefined) {
location += ':' + lineno
}

if (colno !== undefined) {
location += ':' + colno
}

return location
}

// error during js file loading (most likely syntax error)
// we are not going to execute at all
this.error = function (msg, url, line) {
var message = msg
// we are not going to execute at all. `window.onerror` callback.
this.error = function (messageOrEvent, source, lineno, colno, error) {
var message = messageOrEvent
var location = getLocation(source, lineno, colno)

if (location !== '') {
message += '\nat ' + location
}

if (url) {
message = msg + '\nat ' + url + (line ? ':' + line : '')
if (error) {
message += '\n\n' + error.stack
}

socket.emit('karma_error', message)
Expand Down

0 comments on commit 523d608

Please sign in to comment.