Skip to content

Commit

Permalink
refactor(Telemetry): Increase error location coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 1, 2021
1 parent be08323 commit 7264d16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/utils/telemetry/resolve-error-location.js
Expand Up @@ -14,8 +14,8 @@ const resolveErrorLocation = (exceptionTokens) => {
const match = line.match(stacktraceLineRegex) || [];
const matchedPath = match[1] || match[2];
if (matchedPath) {
// Limited to maximum 5 lines in location
if (stacktracePaths.push(matchedPath) === 5) break;
// Limited to maximum 7 lines in location
if (stacktracePaths.push(matchedPath) === 7) break;
} else if (stacktracePaths.length) break;
}

Expand Down
16 changes: 14 additions & 2 deletions test/unit/lib/utils/telemetry/resolve-error-location.test.js
Expand Up @@ -57,7 +57,7 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => {
);
});

it('should return at most 5 lines', () => {
it('should return at most 7 lines', () => {
const err = new Error('test');
err.stack =
'Error:\n' +
Expand All @@ -66,6 +66,10 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => {
' at Test.Runnable.run (/home/xxx/serverless/node_modules/mocha/lib/runnable.js:354:5)\n' +
' at Runner.runTest (/home/xxx/serverless/node_modules/mocha/lib/runner.js:677:10)\n' +
' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:801:12)\n' +
' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:802:12)\n' +
' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:803:12)\n' +
' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:804:12)\n' +
' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:805:12)\n' +
' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:594:14)\n';
const result = resolveErrorLocation(tokenizeException(err));
expect(result).to.equal(
Expand All @@ -75,6 +79,8 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => {
'^:354:5',
'/node_modules/mocha/lib/runner.js:677:10',
'^:801:12',
'^:802:12',
'^:803:12',
].join('\n')
);
});
Expand All @@ -101,7 +107,7 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => {
);
});

it('should return at most 5 lines and use `/` path separator', () => {
it('should return at most 7 lines and use `/` path separator', () => {
const err = new Error('test');
err.stack =
'Error:\n' +
Expand All @@ -110,6 +116,10 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => {
' at Test.Runnable.run (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runnable.js:354:5)\r\n' +
' at Runner.runTest (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:677:10)\r\n' +
' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:801:12)\r\n' +
' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:802:12)\r\n' +
' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:803:12)\r\n' +
' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:804:12)\r\n' +
' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:805:12)\r\n' +
' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:594:14)\r\n';
const result = resolveErrorLocation(tokenizeException(err));
expect(result).to.equal(
Expand All @@ -119,6 +129,8 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => {
'^:354:5',
'/node_modules/mocha/lib/runner.js:677:10',
'^:801:12',
'^:802:12',
'^:803:12',
].join('\n')
);
});
Expand Down

0 comments on commit 7264d16

Please sign in to comment.