Skip to content

Commit 14489ea

Browse files
committed
fix: Handle custom error names in TraceKit
1 parent f4a2862 commit 14489ea

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

test/vendor/fixtures/captured-errors.js

+6
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,10 @@ CapturedExceptions.CHROME_ELECTRON = {
484484
' at TESTTESTTEST.someMethod (C:\\Users\\user\\path\\to\\file.js:295:108)'
485485
};
486486

487+
CapturedExceptions.CUSTOM_ERROR = {
488+
message: 'test',
489+
name: 'HttpError',
490+
stack: 'HttpError: test\n' + ' at file:///path/to/file.js:19:40'
491+
};
492+
487493
module.exports = CapturedExceptions;

test/vendor/tracekit-parser.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -853,5 +853,18 @@ describe('TraceKit', function() {
853853
column: 108
854854
});
855855
});
856+
857+
it('should parse custom errors', function() {
858+
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.CUSTOM_ERROR);
859+
assert.ok(stackFrames);
860+
assert.deepEqual(stackFrames.stack.length, 1);
861+
assert.deepEqual(stackFrames.stack[0], {
862+
url: 'file:///path/to/file.js',
863+
func: '?',
864+
args: [],
865+
line: 19,
866+
column: 40
867+
});
868+
});
856869
});
857870
});

vendor/TraceKit/tracekit.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -364,26 +364,28 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
364364
// ex.stacktrace = n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'
365365

366366
/**
367-
* Computes stack trace information from the stack property.
368-
* Chrome and Gecko use this property.
369-
* @param {Error} ex
370-
* @return {?Object.<string, *>} Stack trace information.
371-
*/
367+
* Computes stack trace information from the stack property.
368+
* Chrome and Gecko use this property.
369+
* @param {Error} ex
370+
* @return {?Object.<string, *>} Stack trace information.
371+
*/
372372
function computeStackTraceFromStackProp(ex) {
373373
if (typeof ex.stack === 'undefined' || !ex.stack) return;
374374

375-
var chrome = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[a-z]:|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,
376-
gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,
377-
winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx(?:-web)|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
378-
// Used to additionally parse URL/line/column from eval frames
379-
geckoEval = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i,
380-
chromeEval = /\((\S*)(?::(\d+))(?::(\d+))\)/,
381-
lines = ex.stack.split('\n'),
382-
stack = [],
383-
submatch,
384-
parts,
385-
element,
386-
reference = /^(.*) is undefined$/.exec(ex.message);
375+
var chrome = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[a-z]:|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
376+
var winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx(?:-web)|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
377+
// NOTE: blob urls are now supposed to always have an origin, therefore it's format
378+
// which is `blob:http://url/path/with-some-uuid`, is matched by `blob.*?:\/` as well
379+
var gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource).*?:\/.*?|\[native code\]|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
380+
// Used to additionally parse URL/line/column from eval frames
381+
var geckoEval = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
382+
var chromeEval = /\((\S*)(?::(\d+))(?::(\d+))\)/;
383+
var lines = ex.stack.split('\n');
384+
var stack = [];
385+
var submatch;
386+
var parts;
387+
var element;
388+
var reference = /^(.*) is undefined$/.exec(ex.message);
387389

388390
for (var i = 0, j = lines.length; i < j; ++i) {
389391
if ((parts = chrome.exec(lines[i]))) {

0 commit comments

Comments
 (0)