Reporting top 3 lines of stack for js errors

This should help investigating js errors. It includes line, column
and names of two functions who calls method with js error.

Change-Id: Icc893161e9c9bb0cde4ec2aecd96fe5e71d780f3
This commit is contained in:
Milutin Kristofic
2019-09-04 11:39:43 +02:00
parent cbbedcdc45
commit 6fbe4b93d1
2 changed files with 17 additions and 1 deletions

View File

@@ -116,7 +116,13 @@
if (error) {
line = line || error.lineNumber;
column = column || error.columnNumber;
msg = msg || error.toString();
let shortenedErrorStack = msg;
if (error.stack) {
const errorStackLines = error.stack.split('\n');
shortenedErrorStack = errorStackLines.slice(0,
Math.min(3, errorStackLines.length)).join('\n');
}
msg = shortenedErrorStack || error.toString();
}
const payload = {
url,

View File

@@ -341,6 +341,7 @@ limitations under the License.
test('is reported', () => {
const error = new Error('bar');
error.stack = undefined;
emulateThrow('bar', 'http://url', 4, 2, error);
assert.isTrue(reporter.calledWith('error', 'exception', 'bar'));
const payload = reporter.lastCall.args[3];
@@ -352,6 +353,15 @@ limitations under the License.
});
});
test('is reported with 3 lines of stack', () => {
const error = new Error('bar');
emulateThrow('bar', 'http://url', 4, 2, error);
const expectedStack = error.stack.split('\n').slice(0, 3)
.join('\n');
assert.isTrue(reporter.calledWith('error', 'exception',
expectedStack));
});
test('prevent default event handler', () => {
assert.isTrue(emulateThrow());
});