File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -571,6 +571,14 @@ Raven.prototype = {
571571
572572 // stack[0] is `throw new Error(msg)` call itself, we are interested in the frame that was just before that, stack[1]
573573 var initialCall = isArray ( stack . stack ) && stack . stack [ 1 ] ;
574+
575+ // if stack[1] is `Raven.captureException`, it means that someone passed a string to it and we redirected that call
576+ // to be handled by `captureMessage`, thus `initialCall` is the 3rd one, not 2nd
577+ // initialCall => captureException(string) => captureMessage(string)
578+ if ( initialCall && initialCall . func === 'Raven.captureException' ) {
579+ initialCall = stack . stack [ 2 ] ;
580+ }
581+
574582 var fileurl = ( initialCall && initialCall . url ) || '' ;
575583
576584 if (
Original file line number Diff line number Diff line change @@ -3015,6 +3015,30 @@ describe('Raven (public API)', function() {
30153015 assert . isTrue ( Raven . _send . calledOnce ) ;
30163016 } ) ;
30173017
3018+ it ( 'should use 3rd frame from stack to get a fileurl if captureMessage was just a redirect from captureException' , function ( ) {
3019+ this . sinon . stub ( Raven , '_send' ) ;
3020+ var TraceKitStub = this . sinon . stub ( TraceKit , 'computeStackTrace' ) ;
3021+ TraceKitStub . returns ( {
3022+ stack : [
3023+ { url : 'http://example.com' , func : 'Raven.captureMessage' } ,
3024+ { url : 'http://example.com' , func : 'Raven.captureException' } ,
3025+ { url : '<anonymous>' , func : '?' }
3026+ ]
3027+ } ) ;
3028+ Raven . _globalOptions . whitelistUrls = {
3029+ test : function ( ) {
3030+ return false ;
3031+ }
3032+ } ;
3033+ this . sinon . spy ( Raven . _globalOptions . whitelistUrls , 'test' ) ;
3034+ this . sinon . spy ( Raven , 'captureMessage' ) ;
3035+
3036+ Raven . captureException ( 'some string' ) ;
3037+
3038+ assert . isTrue ( Raven . captureMessage . calledWith ( 'some string' ) ) ;
3039+ assert . isTrue ( Raven . _globalOptions . whitelistUrls . test . calledWith ( '<anonymous>' ) ) ;
3040+ } ) ;
3041+
30183042 describe ( 'synthetic traces' , function ( ) {
30193043 function assertSynthetic ( frames ) {
30203044 // Raven.captureMessage
You can’t perform that action at this time.
0 commit comments