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

Do not cast to string Error#stack. #464

Merged
merged 1 commit into from
Jul 29, 2018
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
4 changes: 3 additions & 1 deletion pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ function asJson (obj, msg, num, time) {
var notHasOwnProperty = obj.hasOwnProperty === undefined
if (objError) {
data += ',"type":"Error"'
data += obj.stack ? ',"stack":' + this.stringify(obj.stack) : ''
if (obj.stack !== undefined) {
data += ',"stack":' + this.stringify(obj.stack)
}
}
// if global serializer is set, call it first
if (this.serializers[Symbol.for('pino.*')]) {
Expand Down
16 changes: 16 additions & 0 deletions test/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,19 @@ test('stack is omitted if it is not set on err', t => {
instance.level = name
instance[name](err)
})

test('stack is rendered as any other property if it\'s not a string', t => {
t.plan(3)
var err = new Error('myerror')
err.stack = null
var instance = pino(sink(function (chunk, enc, cb) {
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
delete chunk.time
t.equal(chunk.hasOwnProperty('stack'), true)
t.equal(chunk.stack, null)
cb()
}))

instance.level = name
instance[name](err)
})