Skip to content

Commit fcfff34

Browse files
committed
Fix exception when global Error.stackTraceLimit is too low
fixes #9
1 parent 17cb642 commit fcfff34

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Fix exception when global `Error.stackTraceLimit` is too low
5+
16
0.4.2 / 2014-07-19
27
==================
38

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,18 @@ function formatLocation(callSite) {
363363
*/
364364

365365
function getStack() {
366+
var limit = Error.stackTraceLimit
366367
var obj = {}
367368
var prep = Error.prepareStackTrace
368369

369370
Error.prepareStackTrace = prepareObjectStackTrace
371+
Error.stackTraceLimit = Math.max(10, limit)
370372
Error.captureStackTrace(obj, getStack)
371373

372374
var stack = obj.stack
373375

374376
Error.prepareStackTrace = prep
377+
Error.stackTraceLimit = limit
375378

376379
return stack
377380
}

test/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ describe('deprecate(message)', function () {
4040
stderr.should.match(/\.js:[0-9]+:[0-9]+/)
4141
})
4242

43+
it('should log call site regardless of Error.stackTraceLimit', function () {
44+
function callold() { mylib.old() }
45+
var limit = Error.stackTraceLimit
46+
try {
47+
Error.stackTraceLimit = 1
48+
var stderr = captureStderr(callold)
49+
stderr.should.containEql(basename(__filename))
50+
stderr.should.match(/\.js:[0-9]+:[0-9]+/)
51+
} finally {
52+
Error.stackTraceLimit = limit
53+
}
54+
})
55+
4356
it('should log call site within eval', function () {
4457
function callold() { eval('mylib.old()') }
4558
var stderr = captureStderr(callold)

0 commit comments

Comments
 (0)