From 784eb0859fcb3a304a5d34ddcecb139da29d0689 Mon Sep 17 00:00:00 2001 From: Simon Wade Date: Mon, 5 May 2014 16:50:28 +1000 Subject: [PATCH] Sending a log message with a non-object value for the `req` property to the `bunyan` CLI causes it to crash with an `Object.keys called on non-object` message. This change fixes that. --- bin/bunyan | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/bunyan b/bin/bunyan index 54e4055..f7c581c 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -754,14 +754,21 @@ function emitRecord(rec, line, opts, stylize) { var req = rec.req; delete rec.req; var headers = req.headers; + if (!headers) { + headers = ''; + } + else if (typeof headers === 'string') { + headers = '\n' + headers; + } + else if (typeof headers === 'object') { + headers = '\n' + Object.keys(headers).map(function (h) { + return h + ': ' + headers[h]; + }).join('\n'); + } var s = format('%s %s HTTP/%s%s', req.method, req.url, req.httpVersion || '1.1', - (headers ? - '\n' + Object.keys(headers).map(function (h) { - return h + ': ' + headers[h]; - }).join('\n') : - '') + headers ); delete req.url; delete req.method;