Skip to content

Commit 897c59c

Browse files
committed
Merge pull request #87 from rcoup/captureError-stack
Capture stack traces when captureError() is called without an Error object
2 parents 2a500d2 + 17354d7 commit 897c59c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/client.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ _.captureException = function captureError(err, kwargs, cb) {
115115
if(!(err instanceof Error)) {
116116
// This handles when someone does:
117117
// throw "something awesome";
118-
// We just send the "Error" as a normal message
119-
// since there is no way to compute a stack trace
120-
// See: https://github.com/mattrobenolt/raven-node/issues/18
121-
return this.captureMessage('Error: ' + err, kwargs, cb);
118+
// We synthesize an Error here so we can extract a (rough) stack trace.
119+
var err = new Error(err);
122120
}
123121

124122
var self = this;

test/raven.client.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,16 @@ describe('raven.Client', function(){
190190
client.captureError(new Error('wtf?'));
191191
});
192192

193-
it('should send a plain text "error" as a Message instead', function(done){
194-
// See: https://github.com/mattrobenolt/raven-node/issues/18
195-
var old = client.captureMessage;
196-
client.captureMessage = function(message) {
197-
// I'm also appending "Error: " to the beginning to help hint
198-
message.should.equal('Error: wtf?');
193+
it('should send a plain text "error" with a synthesized stack', function(done){
194+
var old = client.send;
195+
client.send = function mockSend(kwargs) {
196+
client.send = old;
197+
198+
kwargs['message'].should.equal("Error: wtf?");
199+
kwargs.should.have.property('sentry.interfaces.Stacktrace');
200+
var stack = kwargs['sentry.interfaces.Stacktrace'];
201+
stack.frames[stack.frames.length-1]['function'].should.equal('Client.captureError');
199202
done();
200-
client.captureMessage = old;
201203
};
202204
client.captureError('wtf?');
203205
});

0 commit comments

Comments
 (0)