Skip to content

Commit

Permalink
v1.8.3. Fix log.info(null) crash that resulted from #426 in v1.8.2.
Browse files Browse the repository at this point in the history
Fixes #450
  • Loading branch information
trentm committed Oct 18, 2016
1 parent a41539b commit 2390bf8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bin/bunyan
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions lib/bunyan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
30 changes: 25 additions & 5 deletions test/log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, null);
var rec = catcher.records[catcher.records.length - 1];
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, e);
log3[lvl].call(log3, null, 'my message');
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, 'my message',
format('log.%s msg: got %j', lvl, rec.msg));
});
t.end();
});

0 comments on commit 2390bf8

Please sign in to comment.