Skip to content

Commit

Permalink
Do not cast to string Error#stack. (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina authored Jul 29, 2018
1 parent 2f14f6d commit 576c970
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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)
})

0 comments on commit 576c970

Please sign in to comment.