From 523d60866a2ec16bf897a5631e6cf12ca7971e9c Mon Sep 17 00:00:00 2001 From: Brian Di Palma Date: Tue, 22 Aug 2017 13:34:23 +0100 Subject: [PATCH] feat(client): log global error stack trace Closes #2812 --- client/karma.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/client/karma.js b/client/karma.js index 7830eec03..ca4663cf8 100644 --- a/client/karma.js +++ b/client/karma.js @@ -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)