Skip to content

Commit

Permalink
Merge pull request #87 from rcoup/captureError-stack
Browse files Browse the repository at this point in the history
Capture stack traces when captureError() is called without an Error object
  • Loading branch information
mattrobenolt committed Sep 9, 2014
2 parents 2a500d2 + 17354d7 commit 897c59c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 2 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ _.captureException = function captureError(err, kwargs, cb) {
if(!(err instanceof Error)) {
// This handles when someone does:
// throw "something awesome";
// We just send the "Error" as a normal message
// since there is no way to compute a stack trace
// See: https://github.com/mattrobenolt/raven-node/issues/18
return this.captureMessage('Error: ' + err, kwargs, cb);
// We synthesize an Error here so we can extract a (rough) stack trace.
var err = new Error(err);
}

var self = this;
Expand Down
16 changes: 9 additions & 7 deletions test/raven.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,16 @@ describe('raven.Client', function(){
client.captureError(new Error('wtf?'));
});

it('should send a plain text "error" as a Message instead', function(done){
// See: https://github.com/mattrobenolt/raven-node/issues/18
var old = client.captureMessage;
client.captureMessage = function(message) {
// I'm also appending "Error: " to the beginning to help hint
message.should.equal('Error: wtf?');
it('should send a plain text "error" with a synthesized stack', function(done){
var old = client.send;
client.send = function mockSend(kwargs) {
client.send = old;

kwargs['message'].should.equal("Error: wtf?");
kwargs.should.have.property('sentry.interfaces.Stacktrace');
var stack = kwargs['sentry.interfaces.Stacktrace'];
stack.frames[stack.frames.length-1]['function'].should.equal('Client.captureError');
done();
client.captureMessage = old;
};
client.captureError('wtf?');
});
Expand Down

0 comments on commit 897c59c

Please sign in to comment.