diff --git a/example/scratch.js b/example/scratch.js index 9f1fa27dbcd9..68edcdb7b815 100644 --- a/example/scratch.js +++ b/example/scratch.js @@ -45,3 +45,19 @@ function showDialog() { broken(); Raven.showReportDialog(); } + +function a() { b(); } +function b() { c(); } +function c() { d(); } +function d() { e(); } +function e() { f(); } +function f() { g(); } +function g() { h(); } +function h() { i(); } +function i() { j(); } +function j() { k(); } +function k() { l(); } +function l() { m(); } +function m() { n(); } +function n() { o(); } +function o() { throw new Error('dang'); } diff --git a/src/raven.js b/src/raven.js index 7cbbdc6e7cc3..3a2ef40f507d 100644 --- a/src/raven.js +++ b/src/raven.js @@ -45,10 +45,12 @@ function Raven() { includePaths: [], crossOrigin: 'anonymous', collectWindowErrors: true, - maxMessageLength: 0 + maxMessageLength: 0, + stackTraceLimit: 50 }; this._ignoreOnError = 0; this._isRavenInstalled = false; + this._originalErrorStackTraceLimit = Error.stackTraceLimit; // capture references to window.console *and* all its methods first // before the console plugin has a chance to monkey patch this._originalConsole = window.console || {}; @@ -164,6 +166,7 @@ Raven.prototype = { this._isRavenInstalled = true; } + Error.stackTraceLimit = this._globalOptions.stackTraceLimit; return this; }, @@ -269,6 +272,7 @@ Raven.prototype = { this._restoreBuiltIns(); + Error.stackTraceLimit = this._originalErrorStackTraceLimit; this._isRavenInstalled = false; return this; @@ -757,7 +761,7 @@ Raven.prototype = { stackInfo.message, stackInfo.url, stackInfo.lineno, - frames, + frames.slice(0, this._globalOptions.stackTraceLimit), options ); }, diff --git a/test/raven.test.js b/test/raven.test.js index ba2bf7036771..588f8bf7322a 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -1449,6 +1449,29 @@ describe('globals', function() { 'new ', 'hey', 'http://example.com', 10, [], undefined ]); }); + + it('should trim number of frames based on stackTraceLimit', function() { + var frame = {url: 'http://example.com'}; + this.sinon.stub(Raven, '_normalizeFrame').returns(frame); + this.sinon.stub(Raven, '_processException'); + + var stackInfo = { + name: 'Matt', + message: 'hey', + url: 'http://example.com', + lineno: 10, + stack: [ + frame, frame + ] + }; + + Raven._globalOptions.stackTraceLimit = 1; + + Raven._handleStackInfo(stackInfo); + assert.deepEqual(Raven._processException.lastCall.args, [ + 'Matt', 'hey', 'http://example.com', 10, [frame], undefined + ]); + }); }); });