Skip to content

Commit

Permalink
Fix exception when global Error.stackTraceLimit is too low
Browse files Browse the repository at this point in the history
fixes #9
  • Loading branch information
dougwilson committed Jul 26, 2014
1 parent 17cb642 commit fcfff34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Fix exception when global `Error.stackTraceLimit` is too low

0.4.2 / 2014-07-19
==================

Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,18 @@ function formatLocation(callSite) {
*/

function getStack() {
var limit = Error.stackTraceLimit
var obj = {}
var prep = Error.prepareStackTrace

Error.prepareStackTrace = prepareObjectStackTrace
Error.stackTraceLimit = Math.max(10, limit)
Error.captureStackTrace(obj, getStack)

var stack = obj.stack

Error.prepareStackTrace = prep
Error.stackTraceLimit = limit

return stack
}
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ describe('deprecate(message)', function () {
stderr.should.match(/\.js:[0-9]+:[0-9]+/)
})

it('should log call site regardless of Error.stackTraceLimit', function () {
function callold() { mylib.old() }
var limit = Error.stackTraceLimit
try {
Error.stackTraceLimit = 1
var stderr = captureStderr(callold)
stderr.should.containEql(basename(__filename))
stderr.should.match(/\.js:[0-9]+:[0-9]+/)
} finally {
Error.stackTraceLimit = limit
}
})

it('should log call site within eval', function () {
function callold() { eval('mylib.old()') }
var stderr = captureStderr(callold)
Expand Down

0 comments on commit fcfff34

Please sign in to comment.