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

Error serializing does not work with nestedKey option #792

Closed
fiznool opened this issue Mar 19, 2020 · 4 comments
Closed

Error serializing does not work with nestedKey option #792

fiznool opened this issue Mar 19, 2020 · 4 comments

Comments

@fiznool
Copy link

fiznool commented Mar 19, 2020

When using the nested key option, error serializing does not appear to work using pino 5.17.0.

To reproduce:

const pino = require('pino');

class TestError extends Error {
  constructor(message) {
    super(`${message}-${Date.now()}`);
    this.code = '501';
  }
}

const testLogger = pino({
  serializers: {
    err: pino.stdSerializers.err,
    error: pino.stdSerializers.err
  }
});

const testLoggerNested = pino({
  nestedKey: 'data',
  serializers: {
    error: pino.stdSerializers.err
  }
});

const error = new TestError('test');

testLogger.error(error, 'Testing with top-level error');
testLogger.error({ err: error }, 'Testing with error inside object with err key');
testLogger.error({ error: error }, 'Testing with error inside object with error key');

testLoggerNested.error(error, 'Nested key testing with top-level error');
testLoggerNested.error({ err: error }, 'Nested key testing with error inside object with err key');
testLoggerNested.error({ error: error }, 'Nested key testing with error inside object with error key');

Running this through pino-pretty yields:

ERROR (76863 on <redacted>): Testing with top-level error
    Error: test-1584625355518
        at Object.<anonymous> (<redacted>/pino-error-test/index.js:24:15)
        at Module._compile (internal/modules/cjs/loader.js:1151:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
        at Module.load (internal/modules/cjs/loader.js:1000:32)
        at Function.Module._load (internal/modules/cjs/loader.js:899:14)
        at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
        at internal/main/run_main_module.js:17:47
ERROR (76863 on <redacted>): Testing with error inside object with err key
    err: {
      "type": "TestError",
      "message": "test-1584625355518",
      "stack":
          Error: test-1584625355518
              at Object.<anonymous> (<redacted>/pino-error-test/index.js:24:15)
              at Module._compile (internal/modules/cjs/loader.js:1151:30)
              at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
              at Module.load (internal/modules/cjs/loader.js:1000:32)
              at Function.Module._load (internal/modules/cjs/loader.js:899:14)
              at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
              at internal/main/run_main_module.js:17:47
      "code": "501"
    }
ERROR (76863 on <redacted>): Testing with error inside object with error key
    error: {
      "type": "TestError",
      "message": "test-1584625355518",
      "stack":
          Error: test-1584625355518
              at Object.<anonymous> (<redacted>/pino-error-test/index.js:24:15)
              at Module._compile (internal/modules/cjs/loader.js:1151:30)
              at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
              at Module.load (internal/modules/cjs/loader.js:1000:32)
              at Function.Module._load (internal/modules/cjs/loader.js:899:14)
              at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
              at internal/main/run_main_module.js:17:47
      "code": "501"
    }
ERROR (76863 on <redacted>): Nested key testing with top-level error
    data: {
      "code": "501"
    }
ERROR (76863 on <redacted>): Nested key testing with error inside object with err key
    data: {
      "err": {
        "code": "501"
      }
    }
ERROR (76863 on <redacted>): Nested key testing with error inside object with error key
    data: {
      "error": {
        "code": "501"
      }
    }
@jsumners
Copy link
Member

Duplicate #771

@fiznool
Copy link
Author

fiznool commented Mar 19, 2020

Thanks and sorry for not searching properly through the issue tracker.

I understand the original issue and the workaround, but I'm a little confused as to why this scenario isn't catered for out of the box. It seems like it might provide a better developer experience. Would a PR that provides this functionality be considered?

@jsumners
Copy link
Member

PRs to improve things are always welcome. Any PR should target the next branch at this current time until v6 is released.

@github-actions
Copy link

github-actions bot commented Feb 6, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants