Skip to content

Commit a82d153

Browse files
committed
Capture stack traces via synthesized errors when required.
When captureError() is called without an Error object, synthesize one so we can grab an approximate stack trace.
1 parent 7bbab6e commit a82d153

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
@@ -110,10 +110,8 @@ _.captureException = function captureError(err, kwargs, cb) {
110110
if(!(err instanceof Error)) {
111111
// This handles when someone does:
112112
// throw "something awesome";
113-
// We just send the "Error" as a normal message
114-
// since there is no way to compute a stack trace
115-
// See: https://github.com/mattrobenolt/raven-node/issues/18
116-
return this.captureMessage('Error: ' + err, kwargs, cb);
113+
// We synthesize an Error here so we can extract a (rough) stack trace.
114+
var err = new Error(err);
117115
}
118116

119117
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(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[0]['function'].should.equal('captureError');
199202
done();
200-
client.captureMessage = old;
201203
};
202204
client.captureError('wtf?');
203205
});

0 commit comments

Comments
 (0)