Skip to content

Commit ae422e9

Browse files
committed
Pass stacktrace via captureMessage as stacktrace interface
1 parent 6dc5dcb commit ae422e9

File tree

3 files changed

+58
-41
lines changed

3 files changed

+58
-41
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module.exports = function(grunt) {
132132
dest: 'build/raven.test.js',
133133
options: {
134134
browserifyOptions: {
135-
debug: true // source maps
135+
debug: false// source maps
136136
},
137137
ignore: ['react-native'],
138138
plugin: [proxyquire.plugin]

src/raven.js

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,18 @@ Raven.prototype = {
362362
* @return {Raven}
363363
*/
364364
captureMessage: function(msg, options) {
365-
if (options.stacktrace) {
365+
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
366+
// early call; we'll error on the side of logging anything called before configuration since it's
367+
// probably something you should see:
368+
if (!!this._globalOptions.ignoreErrors.test && this._globalOptions.ignoreErrors.test(msg)) {
369+
return;
370+
}
371+
372+
var data = objectMerge({
373+
message: msg + '' // Make sure it's actually a string
374+
}, options);
375+
376+
if (options && options.stacktrace) {
366377
var ex;
367378
// create a stack trace from this point; just trim
368379
// off extra frames so they don't include this function call (or
@@ -384,26 +395,16 @@ Raven.prototype = {
384395
trimTailFrames: (options.trimHeadFrames || 0) + 1
385396
}, options);
386397

387-
// infinite loop if ex *somehow* returns false for isError
388-
// is that possible when it is result of try/catch?
389-
this.captureException(ex, options);
390-
391-
return this;
392-
}
393-
394-
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
395-
// early call; we'll error on the side of logging anything called before configuration since it's
396-
// probably something you should see:
397-
if (!!this._globalOptions.ignoreErrors.test && this._globalOptions.ignoreErrors.test(msg)) {
398-
return;
398+
var stack = TraceKit.computeStackTrace(ex);
399+
var frames = this._buildNormalizedFrames(stack, options);
400+
data.stacktrace = {
401+
// Sentry expects frames oldest to newest
402+
frames: frames.reverse()
403+
}
399404
}
400405

401406
// Fire away!
402-
this._send(
403-
objectMerge({
404-
message: msg + '' // Make sure it's actually a string
405-
}, options)
406-
);
407+
this._send(data);
407408

408409
return this;
409410
},
@@ -1101,9 +1102,26 @@ Raven.prototype = {
11011102
},
11021103

11031104
_handleStackInfo: function(stackInfo, options) {
1105+
var frames = this._prepareFrames(stackInfo, options);
1106+
1107+
this._triggerEvent('handle', {
1108+
stackInfo: stackInfo,
1109+
options: options
1110+
});
1111+
1112+
this._processException(
1113+
stackInfo.name,
1114+
stackInfo.message,
1115+
stackInfo.url,
1116+
stackInfo.lineno,
1117+
frames,
1118+
options
1119+
);
1120+
},
1121+
1122+
_prepareFrames: function(stackInfo, options) {
11041123
var self = this;
11051124
var frames = [];
1106-
11071125
if (stackInfo.stack && stackInfo.stack.length) {
11081126
each(stackInfo.stack, function(i, stack) {
11091127
var frame = self._normalizeFrame(stack);
@@ -1113,30 +1131,25 @@ Raven.prototype = {
11131131
});
11141132

11151133
// e.g. frames captured via captureMessage throw
1116-
if (options.trimHeadFrames) {
1117-
frames = frames.slice(options.trimHeadFrames);
1134+
var j;
1135+
if (options && options.trimHeadFrames) {
1136+
for (j = 0; j < options.trimHeadFrames && j < frames.length; j++) {
1137+
frames[j].in_app = true;
1138+
}
11181139
}
1140+
11191141
// e.g. try/catch (wrapper) frames
1120-
if (options.trimTailFrames) {
1121-
frames = frames.slice(0, options.trimTailFrames);
1142+
if (options && options.trimTailFrames) {
1143+
for (j = options.trimTailFrames; j < frames.length; j++) {
1144+
frames[j].in_app = true;
1145+
}
11221146
}
11231147
}
1124-
1125-
this._triggerEvent('handle', {
1126-
stackInfo: stackInfo,
1127-
options: options
1128-
});
1129-
1130-
this._processException(
1131-
stackInfo.name,
1132-
stackInfo.message,
1133-
stackInfo.url,
1134-
stackInfo.lineno,
1135-
frames.slice(0, this._globalOptions.stackTraceLimit),
1136-
options
1137-
);
1148+
frames = frames.slice(0, this._globalOptions.stackTraceLimit);
1149+
return frames;
11381150
},
11391151

1152+
11401153
_normalizeFrame: function(frame) {
11411154
if (!frame.url) return;
11421155

@@ -1162,7 +1175,6 @@ Raven.prototype = {
11621175

11631176
_processException: function(type, message, fileurl, lineno, frames, options) {
11641177
var stacktrace;
1165-
11661178
if (!!this._globalOptions.ignoreErrors.test && this._globalOptions.ignoreErrors.test(message)) return;
11671179

11681180
message += '';

test/raven.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,10 @@ describe('Raven (public API)', function() {
17571757
Raven.context({foo: 'bar'}, broken);
17581758
}, error);
17591759
assert.isTrue(Raven.captureException.called);
1760-
assert.deepEqual(Raven.captureException.lastCall.args, [error, {'foo': 'bar'}]);
1760+
assert.deepEqual(Raven.captureException.lastCall.args, [error, {
1761+
'foo': 'bar',
1762+
trimTailFrames: 1 // because wrap
1763+
}]);
17611764
});
17621765

17631766
it('should capture the exception without options', function() {
@@ -1768,7 +1771,9 @@ describe('Raven (public API)', function() {
17681771
Raven.context(broken);
17691772
}, error);
17701773
assert.isTrue(Raven.captureException.called);
1771-
assert.deepEqual(Raven.captureException.lastCall.args, [error, undefined]);
1774+
assert.deepEqual(Raven.captureException.lastCall.args, [error, {
1775+
trimTailFrames: 1 // because wrap
1776+
}]);
17721777
});
17731778

17741779
it('should execute the callback without arguments', function() {

0 commit comments

Comments
 (0)