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
diff --git a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting.js b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting.js
index ca494d2..397189a 100644
--- a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting.js
+++ b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting.js
@@ -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,
diff --git a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
index f505311..a0a25b3 100644
--- a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
+++ b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
@@ -341,6 +341,7 @@
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 @@
});
});
+ 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());
});