Skip to content

Commit a64e907

Browse files
committed
don't remove anonymous functions from stack trace
TraceKit's stacktrace regex for Chrome didn't match anonymous functions, so all anonymous functions in the stacktrace were being removed before reporting to Sentry. This caused errors to be attributed to the wrong files, and was generally extremely confusing. This change updates the regex to not *require* a function name be present in the stacktrace.
1 parent f6e8cbe commit a64e907

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

test/raven.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ function now() {
5050
}
5151

5252
describe('TraceKit', function(){
53+
describe('stacktrace info', function() {
54+
"use strict";
55+
var trace;
56+
it('should not remove anonymous functions from the stack', function() {
57+
var obj = {};
58+
try {
59+
(function namedFunc4() { // stack[4]
60+
(function () { // stack[3]
61+
(function namedFunc2() { // stack[2]
62+
(function () { // stack[1]
63+
(function namedFunc0() { // stack[0]
64+
throw new Error();
65+
}());
66+
}());
67+
}());
68+
}());
69+
}());
70+
} catch(ex) {
71+
trace = TraceKit.computeStackTrace(ex);
72+
73+
// Make sure TraceKit didn't remove the anonymous functions
74+
// from the stack like it used to :)
75+
assert.equal(trace.stack[0].func, 'namedFunc0');
76+
assert.equal(trace.stack[1].func, '?');
77+
assert.equal(trace.stack[2].func, 'namedFunc2');
78+
assert.equal(trace.stack[3].func, '?');
79+
assert.equal(trace.stack[4].func, 'namedFunc4');
80+
}
81+
});
82+
});
5383
describe('error notifications', function(){
5484
var testMessage = "__mocha_ignore__";
5585
var subscriptionHandler;

vendor/TraceKit/tracekit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
631631
return null;
632632
}
633633

634-
var chrome = /^\s*at (.+?) ?\(?((?:file|https?|chrome-extension):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
634+
var chrome = /^\s*at (\S*) ?\(?((?:file|https?|chrome-extension):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
635635
gecko = /^\s*(.*?)(?:\((.*?)\))?@((?:file|https?|chrome).*?):(\d+)(?::(\d+))?\s*$/i,
636636
lines = ex.stack.split('\n'),
637637
stack = [],

0 commit comments

Comments
 (0)