Pino: TypeError: this[writeSym] is not a function

Created on 16 Nov 2018  路  7Comments  路  Source: pinojs/pino

Hi,

For some time now, I've been watching an node appliation crash because of this error:

2018-11-01T23:17:32.681112810Z /home/node/app/node_modules/pino/lib/tools.js:39
2018-11-01T23:17:32.681308955Z       this[writeSym](o, format(null, n, this[formatOptsSym]), z)
2018-11-01T23:17:32.681358278Z                     ^
2018-11-01T23:17:32.681403017Z
2018-11-01T23:17:32.681445726Z TypeError: this[writeSym] is not a function
2018-11-01T23:17:32.681489423Z     at Client.LOG (/home/node/app/node_modules/pino/lib/tools.js:39:21)
2018-11-01T23:17:32.681544267Z     at Client.emit (events.js:182:13)
2018-11-01T23:17:32.681588694Z     at WebSocketConnection.onError (/home/node/app/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:374:17)
2018-11-01T23:17:32.681729683Z     at WebSocket.onError (/home/node/app/node_modules/ws/lib/event-target.js:128:16)
2018-11-01T23:17:32.681783537Z     at WebSocket.emit (events.js:182:13)
2018-11-01T23:17:32.681824266Z     at _receiver.cleanup (/home/node/app/node_modules/ws/lib/websocket.js:211:14)
2018-11-01T23:17:32.681865725Z     at Receiver.cleanup (/home/node/app/node_modules/ws/lib/receiver.js:557:13)
2018-11-01T23:17:32.681906610Z     at WebSocket.finalize (/home/node/app/node_modules/ws/lib/websocket.js:206:20)
2018-11-01T23:17:32.681948016Z     at TLSSocket.emit (events.js:182:13)
2018-11-01T23:17:32.681988120Z     at emitErrorNT (internal/streams/destroy.js:82:8)
2018-11-01T23:17:32.682038120Z     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
2018-11-01T23:17:32.682079474Z     at process._tickCallback (internal/process/next_tick.js:63:19)

I have no idea why or how this error is happening. The only thing I think I've been able to determine is that it's intrasequentially related to Pino. The code causing this error is available here.

Sorry for the inconvenience,

Most helpful comment

As David said, in your example you are not retaining the internal this Pino uses. You at the very least need to logger.info.bind(logger).

All 7 comments

Can you please include a full repro? When is this happening?

I do not know when this error happens, I did not find any correlation with other events. The code base is here and the faulty system is here.

I鈥檓 sorry I can鈥檛 be of more help, but I need a repro.

Just as a tip - it's likely that what's happened is you've taken the log method off of the pino instance - e.g. const { info } = pino(). In that example calling info on its own will result in this exact error.

I spoke with a member of the project and I think I have identified where the error comes from. But that is just a guess.

@mcolina It is impossible to make a reproduction when we have no idea where the message comes from. The only thing I can give is the link of the project.

Thanks for your help ^^

I encountered this issue by wanting to use pino to override the default apostrophe logger. For people who are looking for the origin of the problem on their side, here is a way to reproduce it.

const pino = require('pino')

const logger = pino({
  level: 'debug'
})

const methods = {
  info: logger.info
}

methods.info('Hello')
TypeError: this[writeSym] is not a function
    at Object.LOG [as info] (/home/runner/node_modules/pino/lib/tools.js:36:26)
    at ...

As David said, in your example you are not retaining the internal this Pino uses. You at the very least need to logger.info.bind(logger).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

afgallo picture afgallo  路  4Comments

ptommasi picture ptommasi  路  3Comments

mcollina picture mcollina  路  3Comments

cekvenich picture cekvenich  路  6Comments

JamesKyburz picture JamesKyburz  路  7Comments