Repository: pinojs/pino (js)

Issue:
When an Error is the first parameter, the second and third parameters are not being passed to pino-pretty
Originally thought this was a pretty-pino [issue](https://github.com/pinojs/pino-pretty/issues/27) but it is in-fact a pino issue.

In `prettyPrint` mode when the first argument is an `Error`, pino does not pass the second and/or third arguments to pino-pretty.

Code to re-produce is:

`try { throw new Error('foo') } catch(error) { logger.info(error, 'something went wrong') }`
`try { throw new Error('bar') } catch(error) { logger.info(error, 'something broke', 'test string') }`

Pino only passes the `Error` for the first argument to pretty-pino but not the second or third arguments:

`[1535020164640] INFO (94172 on macbook-pro-2.internal.local): foo
    Error: foo
        at Object.<anonymous>...
`
`[1535020164642] INFO (94172 on macbook-pro-2.internal.local): bar
    Error: bar
        at Object.<anonymous>... 
`

I would expect the second and/or third arguments to be passed along with the first `Error` argument in `prettyPrint` mode.

Versions used were `pino@5.3.0` and `pino-pretty@2.0.1`




Pull request description:
Correctly assemble the message when errors are present
Fixes #500

Patch:
diff --git a/example.js b/example.js
index 19228f2..5e39692 100644
--- a/example.js
+++ b/example.js
@@ -31,3 +31,5 @@ pino.trace('this is a trace statement')
 pino.debug('this is a "debug" statement with "')
 
 pino.info(new Error('kaboom'))
+
+pino.info(new Error('kaboom'), 'with', 'a', 'message')
diff --git a/lib/tools.js b/lib/tools.js
index e0776bd..6d3c400 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -197,7 +197,7 @@ function prettifierMetaWrapper (pretty, dest) {
       var msg = this.lastMsg
 
       if (lastObj instanceof Error) {
-        msg = lastObj.message
+        msg = msg || lastObj.message
         lastObj = {
           type: 'Error',
           stack: lastObj.stack


Test patch:
diff --git a/test/fixtures/pretty/error.js b/test/fixtures/pretty/error.js
index 12be861..7f336b7 100644
--- a/test/fixtures/pretty/error.js
+++ b/test/fixtures/pretty/error.js
@@ -4,3 +4,4 @@ require('os').hostname = function () { return 'abcdefghijklmnopqr' }
 var pino = require(require.resolve('./../../../'))
 var log = pino({prettyPrint: true})
 log.error(new Error('kaboom'))
+log.error(new Error('kaboom'), 'with', 'a', 'message')
diff --git a/test/pretty.test.js b/test/pretty.test.js
index 6c9f8b9..0371028 100644
--- a/test/pretty.test.js
+++ b/test/pretty.test.js
@@ -184,5 +184,6 @@ test('errors', async ({isNot}) => {
   }))
   await once(child, 'close')
   isNot(actual.match(/\(123456 on abcdefghijklmnopqr\): kaboom/), null)
+  isNot(actual.match(/\(123456 on abcdefghijklmnopqr\): with a message/), null)
   isNot(actual.match(/.*error\.js.*/), null)
 })