Skip to content

Commit bc060ae

Browse files
committed
Coerce message passed to captureMessage to a string as well
1 parent 611dc55 commit bc060ae

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/raven.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ var Raven = {
218218
* @return {Raven}
219219
*/
220220
captureException: function(ex, options) {
221-
// If a string is passed through, recall as a message
222-
if (isString(ex)) return Raven.captureMessage(ex, options);
221+
// If not an Error is passed through, recall as a message instead
222+
if (!(ex instanceof Error)) return Raven.captureMessage(ex, options);
223223

224224
// Store the raw exception object for potential debugging and introspection
225225
lastCapturedException = ex;
@@ -251,7 +251,7 @@ var Raven = {
251251
// Fire away!
252252
send(
253253
objectMerge({
254-
message: msg
254+
message: msg + '' // Make sure it's actually a string
255255
}, options)
256256
);
257257

test/raven.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,14 @@ describe('Raven (public API)', function() {
13011301
}]);
13021302
});
13031303

1304+
it('should coerce message to a string', function() {
1305+
this.sinon.stub(window, 'send');
1306+
Raven.captureMessage({});
1307+
assert.deepEqual(window.send.lastCall.args, [{
1308+
message: '[object Object]'
1309+
}]);
1310+
});
1311+
13041312
it('should work as advertised #integration', function() {
13051313
imageCache = [];
13061314
setupRaven();
@@ -1351,12 +1359,15 @@ describe('Raven (public API)', function() {
13511359
}, error);
13521360
});
13531361

1354-
it('should capture as a normal message if a string is passed', function() {
1362+
it('should capture as a normal message if a non-Error is passed', function() {
13551363
this.sinon.stub(Raven, 'captureMessage');
13561364
this.sinon.stub(TraceKit, 'report');
13571365
Raven.captureException('derp');
13581366
assert.equal(Raven.captureMessage.lastCall.args[0], 'derp');
13591367
assert.isFalse(TraceKit.report.called);
1368+
Raven.captureException(true);
1369+
assert.equal(Raven.captureMessage.lastCall.args[0], true);
1370+
assert.isFalse(TraceKit.report.called);
13601371
});
13611372
});
13621373
});

0 commit comments

Comments
 (0)