node-bunyan icon indicating copy to clipboard operation
node-bunyan copied to clipboard

Cannot read property 'getFileName' of undefined

Open krazyjakee opened this issue 8 years ago • 4 comments

This is how I'm using it... promiseFunction().then(doStuff).catch(logger.error)

The result: Cannot read property 'getFileName' of undefined This line: https://github.com/trentm/node-bunyan/blob/master/lib/bunyan.js#L195

What is going wrong here?

krazyjakee avatar Apr 04 '17 16:04 krazyjakee

What is going wrong is that stack trace information is simply not available in some contexts of a promise, therefore the caller variable must be checked before being used.

krazyjakee avatar Apr 05 '17 08:04 krazyjakee

I found this as well. did this solution eventually make it out to a release of the npm module? I am finding it hard to follow the forks. thanks!

jblossom-baker avatar Jan 26 '18 18:01 jblossom-baker

I also ran into this issue. console.error() seems to log these just fine, although ideally I'd like to use Bunyan instead... I'm not really seeing a pattern as to why it would trip Bunyan, the console.error() stack trace seems to provide full context (file name, line number, and function name).

Here is an example of one I bottled up with console.error() and later fixed:

TypeError: module.exports.DB.collection(...).dropCollection is not a function
    at Promise (/batscloud/database/database-mongodb.js:282:45)
    at Object.module.exports.DropCollection (/batscloud/database/database-mongodb.js:280:9)
    at HandleSynchronization.Controller.SynchronizationPatchCache.reconstruct.then (/batscloud/deploymentController/deploymentController.js:243:25)

Maxattax97 avatar Jul 02 '18 17:07 Maxattax97

Try adding this fix here with patch-package (note I haven't tested yet): https://github.com/trentm/node-bunyan/blob/master/lib/bunyan.js#L188

        var caller = stack[2];
        if (!caller) {
          return;
        }

gaberogan avatar Nov 08 '21 15:11 gaberogan