Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ Raven.prototype = {

// stack[0] is `throw new Error(msg)` call itself, we are interested in the frame that was just before that, stack[1]
var initialCall = isArray(stack.stack) && stack.stack[1];

// if stack[1] is `Raven.captureException`, it means that someone passed a string to it and we redirected that call
// to be handled by `captureMessage`, thus `initialCall` is the 3rd one, not 2nd
// initialCall => captureException(string) => captureMessage(string)
if (initialCall && initialCall.func === 'Raven.captureException') {
Copy link
Contributor Author

@kamilogorek kamilogorek Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we shouldn't use /captureException$/ here or not, as someone may use a different object's name when not using our singleton. But it sounds like a very odd edge-case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh, i think this is good unless some minification or babel transform on class or function names could break this string equality

initialCall = stack.stack[2];
}

var fileurl = (initialCall && initialCall.url) || '';

if (
Expand Down
24 changes: 24 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,30 @@ describe('Raven (public API)', function() {
assert.isTrue(Raven._send.calledOnce);
});

it('should use 3rd frame from stack to get a fileurl if captureMessage was just a redirect from captureException', function() {
this.sinon.stub(Raven, '_send');
var TraceKitStub = this.sinon.stub(TraceKit, 'computeStackTrace');
TraceKitStub.returns({
stack: [
{url: 'http://example.com', func: 'Raven.captureMessage'},
{url: 'http://example.com', func: 'Raven.captureException'},
{url: '<anonymous>', func: '?'}
]
});
Raven._globalOptions.whitelistUrls = {
test: function() {
return false;
}
};
this.sinon.spy(Raven._globalOptions.whitelistUrls, 'test');
this.sinon.spy(Raven, 'captureMessage');

Raven.captureException('some string');

assert.isTrue(Raven.captureMessage.calledWith('some string'));
assert.isTrue(Raven._globalOptions.whitelistUrls.test.calledWith('<anonymous>'));
});

describe('synthetic traces', function() {
function assertSynthetic(frames) {
// Raven.captureMessage
Expand Down