Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise catch directly calling error log results in "Cannot read properties of undefined" exception #1962

Open
flyweight opened this issue May 1, 2024 · 1 comment

Comments

@flyweight
Copy link

Unsure if this is purposeful, but I ran into this small issue while replacing some of my existing warning logs.

Test file:

$ cat test.mjs
import pino from 'pino'
const log = pino()
Promise.reject("FAIL").catch(log.error);

Pino Exception:

/tmp/pino/node_modules/pino/lib/tools.js:68
      if (typeof this[msgPrefixSym] === 'string' && msg !== undefined && msg !== null) {
                     ^

TypeError: Cannot read properties of undefined (reading 'Symbol(pino.msgPrefix)')
    at LOG (/tmp/pino/node_modules/pino/lib/tools.js:68:22)

To get it working, you must bind the correct context:

$ cat test.mjs
import pino from 'pino'
const log = pino()
Promise.reject("FAIL").catch(log.error.bind(log));

// OR

Promise.reject("FAIL").catch(e => log.error(e));

Expected result: pino should just log the error without throwing an exception. Thanks

@jsumners jsumners closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2024
@jsumners jsumners reopened this May 2, 2024
@mcollina
Copy link
Member

mcollina commented May 2, 2024

This is expected. Back in the days, .bind() was very expensive, so we avoided it. We would need to check if it's still the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants