mattinsler/longjohn

Asynchronously / lazily accessed err.stack is wrong

Opened this issue · 0 comments

Since stack trace generation is tied to Error.prepareStackTrace, lazily (asynchronously) accessing err.stack causes it be wrong and include both an additional (shouldn't be there) and out of order stack:

require('longjohn')

setTimeout(function() {
  setTimeout(function() {
    var err =new Error('asdf')
    setTimeout(function() {
      console.log(err.stack)
    })
  })
})
Error: asdf
    at [object Object].<anonymous> (/private/tmp/index.js:5:14)
    at listOnTimeout (timers.js:89:15)
---------------------------------------------
    at [object Object].<anonymous> (/private/tmp/index.js:6:5)
    at listOnTimeout (timers.js:89:15)
---------------------------------------------
    at [object Object].<anonymous> (/private/tmp/index.js:4:3)
    at listOnTimeout (timers.js:89:15)
---------------------------------------------
    at Object.<anonymous> (/private/tmp/index.js:3:1)
    at Module._compile (module.js:430:26)
    at Module._extensions..js (module.js:448:10)
    at Module.load (module.js:355:32)
    at Module._load (module.js:310:12)
    at Module.runMain (module.js:471:10)
    at startup (node.js:117:18)
    at node.js:951:3

Note /private/tmp/index.js:6:5 and the line after it, should not be included.