v1.8.3. Fix `log.info(null)` crash that resulted from #426 in v1.8.2.

Fixes #450
master
Trent Mick 2016-10-18 13:13:20 -07:00
parent a41539bfbd
commit 2390bf8df2
5 changed files with 35 additions and 10 deletions

View File

@ -8,6 +8,11 @@ Known issues:
## not yet released
## 1.8.3
- [issue #450] Fix `log.info(null)` crash that resulted from #426 in v1.8.2.
## 1.8.2
- [issue #449] Bump dtrace-provider dep to 0.7.0 to help avoid deprecation
@ -26,7 +31,7 @@ Known issues:
## 1.8.0
Note: *Bad release.* An addition in this release broke 'rotating-file' usage.
Use 1.8.1 instead.
Use 1.8.1 or later.
- [issue #370] Fix `bunyan -p ...` (i.e. DTrace integration) on node
4.x and 5.x.

View File

@ -11,7 +11,7 @@
* vim: expandtab:ts=4:sw=4
*/
var VERSION = '1.8.2';
var VERSION = '1.8.3';
var p = console.log;
var util = require('util');

View File

@ -8,7 +8,7 @@
* vim: expandtab:ts=4:sw=4
*/
var VERSION = '1.8.2';
var VERSION = '1.8.3';
/*
* Bunyan log format version. This becomes the 'v' field on all log records.
@ -980,7 +980,7 @@ function mkLogEmitter(minLevel) {
msgArgs[0] = util.inspect(msgArgs[0]);
} else { // `log.<level>(fields, msg, ...)`
fields = args[0];
if (args.length === 1 && fields.err &&
if (fields && args.length === 1 && fields.err &&
fields.err instanceof Error)
{
msgArgs = [fields.err.message];

View File

@ -1,6 +1,6 @@
{
"name": "bunyan",
"version": "1.8.2",
"version": "1.8.3",
"description": "a JSON logging library for node.js services",
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)",
"main": "./lib/bunyan.js",

View File

@ -239,13 +239,33 @@ test('log.info(<fields>, <array>)', function (t) {
t.end();
});
test('log.info(<err>)', function (t) {
var e = new Error('boom');
/*
* By accident (starting with trentm/node-bunyan#85 in bunyan@0.23.0),
* log.info(null, ...)
* was interpreted as `null` being the object of fields. It is gracefully
* handled, which is good. However, had I to do it again, I would have made
* that interpret `null` as the *message*, and no fields having been passed.
* I think it is baked now. It would take a major bunyan rev to change it,
* but I don't think it is worth it: passing `null` as the first arg isn't
* really an intended way to call these Bunyan methods for either case.
*/
test('log.info(null)', function (t) {
names.forEach(function (lvl) {
log3[lvl].call(log3, e);
log3[lvl].call(log3, null);
var rec = catcher.records[catcher.records.length - 1];
t.equal(rec.err.message, 'boom',
format('log.%s err.message: got %j', lvl, rec.err.message));
t.equal(rec.msg, '', format('log.%s msg: got %j', lvl, rec.msg));
});
t.end();
});
test('log.info(null, <msg>)', function (t) {
names.forEach(function (lvl) {
log3[lvl].call(log3, null, 'my message');
var rec = catcher.records[catcher.records.length - 1];
t.equal(rec.msg, 'my message',
format('log.%s msg: got %j', lvl, rec.msg));
});
t.end();
});