Skip to content
New issue

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

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

Already on GitHub? # to your account

fix msg precendence when sending a merging object with msg and err #1654

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function write (_obj, msg, num) {
}
} else {
obj = _obj
if (msg === undefined && _obj[errorKey]) {
if (msg === undefined && _obj.msg === undefined && _obj[errorKey]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi all, should this be _obj[messageKey] (instead of _obj.msg) since that msg key is configurable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelmukuthu I think that may be true. Can you write a test that proves it and submit a PR to fix?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: #1746. I did two separate git pushes to try and trigger the failing test on CI but it didn't work as approval is needed. Hopefully you'll be able to trigger CI on the first commit!

msg = _obj[errorKey].message
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,23 @@ test('correctly adds msg on error when nestedKey is used', async ({ same }) => {
msg: 'msg message'
})
})

test('msg should take precedence over error message on mergingObject', async ({ same }) => {
const err = new Error('myerror')
const stream = sink()
const instance = pino(stream)
instance.error({ msg: 'my message', err })
const result = await once(stream, 'data')
delete result.time
same(result, {
pid,
hostname,
level: 50,
err: {
type: 'Error',
stack: err.stack,
message: err.message
},
msg: 'my message'
})
})