Skip to content

Commit

Permalink
don't remove anonymous functions from stack trace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mwcz committed Nov 13, 2014
1 parent f6e8cbe commit d94cb5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@ function now() {
}

describe('TraceKit', function(){
describe('stacktrace info', function() {
it('should not remove anonymous functions from the stack', function() {
// mock up an error object with a stack trace that includes both
// named functions and anonymous functions
var stack_str = "" +
" Error: \n" +
" at namedFunc0 (http://example.com/js/script.js:10)\n" + // stack[0]
" at http://example.com/js/test.js:65\n" + // stack[1]
" at namedFunc2 (http://example.com/js/script.js:20)\n" + // stack[2]
" at http://example.com/js/test.js:67\n" + // stack[3]
" at namedFunc4 (http://example.com/js/script.js:100001)"; // stack[4]
var mock_err = { stack: stack_str };
var trace = TraceKit.computeStackTrace.computeStackTraceFromStackProp(mock_err);

// Make sure TraceKit didn't remove the anonymous functions
// from the stack like it used to :)
assert.equal(trace.stack[0].func, 'namedFunc0');
assert.equal(trace.stack[1].func, '?');
assert.equal(trace.stack[2].func, 'namedFunc2');
assert.equal(trace.stack[3].func, '?');
assert.equal(trace.stack[4].func, 'namedFunc4');
});
});
describe('error notifications', function(){
var testMessage = "__mocha_ignore__";
var subscriptionHandler;
Expand Down
3 changes: 2 additions & 1 deletion vendor/TraceKit/tracekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
return null;
}

var chrome = /^\s*at (.+?) ?\(?((?:file|https?|chrome-extension):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
var chrome = /^\s*at (\S*) ?\(?((?:file|https?|chrome-extension):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
gecko = /^\s*(.*?)(?:\((.*?)\))?@((?:file|https?|chrome).*?):(\d+)(?::(\d+))?\s*$/i,
lines = ex.stack.split('\n'),
stack = [],
Expand Down Expand Up @@ -1064,6 +1064,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
}

computeStackTrace.augmentStackTraceWithInitialElement = augmentStackTraceWithInitialElement;
computeStackTrace.computeStackTraceFromStackProp = computeStackTraceFromStackProp;
computeStackTrace.guessFunctionName = guessFunctionName;
computeStackTrace.gatherContext = gatherContext;
computeStackTrace.ofCaller = computeStackTraceOfCaller;
Expand Down

0 comments on commit d94cb5f

Please sign in to comment.