Skip to content

Commit 08bb29d

Browse files
committed
Support setting Error.stackTraceLimit automatically
In V8, `Error.stack` is truncated with a default `Error.stackTraceLimit` of 10. So we want to expose this and set it to Infinity to capture it all.
1 parent 2fffd81 commit 08bb29d

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

example/scratch.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,19 @@ function showDialog() {
4545
broken();
4646
Raven.showReportDialog();
4747
}
48+
49+
function a() { b(); }
50+
function b() { c(); }
51+
function c() { d(); }
52+
function d() { e(); }
53+
function e() { f(); }
54+
function f() { g(); }
55+
function g() { h(); }
56+
function h() { i(); }
57+
function i() { j(); }
58+
function j() { k(); }
59+
function k() { l(); }
60+
function l() { m(); }
61+
function m() { n(); }
62+
function n() { o(); }
63+
function o() { throw new Error('dang'); }

src/raven.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ function Raven() {
4545
includePaths: [],
4646
crossOrigin: 'anonymous',
4747
collectWindowErrors: true,
48-
maxMessageLength: 0
48+
maxMessageLength: 0,
49+
stackTraceLimit: Infinity
4950
};
5051
this._ignoreOnError = 0;
5152
this._isRavenInstalled = false;
53+
this._originalErrorStackTraceLimit = Error.stackTraceLimit;
5254
// capture references to window.console *and* all its methods first
5355
// before the console plugin has a chance to monkey patch
5456
this._originalConsole = window.console || {};
@@ -164,6 +166,7 @@ Raven.prototype = {
164166
this._isRavenInstalled = true;
165167
}
166168

169+
Error.stackTraceLimit = this._globalOptions.stackTraceLimit;
167170
return this;
168171
},
169172

@@ -269,6 +272,7 @@ Raven.prototype = {
269272

270273
this._restoreBuiltIns();
271274

275+
Error.stackTraceLimit = this._originalErrorStackTraceLimit;
272276
this._isRavenInstalled = false;
273277

274278
return this;
@@ -757,7 +761,7 @@ Raven.prototype = {
757761
stackInfo.message,
758762
stackInfo.url,
759763
stackInfo.lineno,
760-
frames,
764+
frames.slice(0, this._globalOptions.stackTraceLimit),
761765
options
762766
);
763767
},

test/raven.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,29 @@ describe('globals', function() {
14491449
'new <anonymous>', 'hey', 'http://example.com', 10, [], undefined
14501450
]);
14511451
});
1452+
1453+
it('should trim number of frames based on stackTraceLimit', function() {
1454+
var frame = {url: 'http://example.com'};
1455+
this.sinon.stub(Raven, '_normalizeFrame').returns(frame);
1456+
this.sinon.stub(Raven, '_processException');
1457+
1458+
var stackInfo = {
1459+
name: 'Matt',
1460+
message: 'hey',
1461+
url: 'http://example.com',
1462+
lineno: 10,
1463+
stack: [
1464+
frame, frame
1465+
]
1466+
};
1467+
1468+
Raven._globalOptions.stackTraceLimit = 1;
1469+
1470+
Raven._handleStackInfo(stackInfo);
1471+
assert.deepEqual(Raven._processException.lastCall.args, [
1472+
'Matt', 'hey', 'http://example.com', 10, [frame], undefined
1473+
]);
1474+
});
14521475
});
14531476
});
14541477

0 commit comments

Comments
 (0)