Make bunyan
defensive on res.header=null
.
Fixes #244. Also add test case for this and a couple recent `bunyan` crashers.
This commit is contained in:
parent
a5bc7911d3
commit
762e26713c
9 changed files with 17 additions and 10 deletions
|
@ -8,7 +8,7 @@ Known issues:
|
|||
|
||||
## bunyan 1.3.6 (not yet released)
|
||||
|
||||
(nothing yet)
|
||||
- [issue #244] Make `bunyan` defensive on `res.header=null`.
|
||||
|
||||
|
||||
## bunyan 1.3.5
|
||||
|
|
|
@ -929,12 +929,10 @@ function emitRecord(rec, line, opts, stylize) {
|
|||
// Typical JSON.stringify of a core node HttpResponse?)
|
||||
var headerTypes = {string: true, object: true};
|
||||
var headers;
|
||||
if (res.header !== undefined && headerTypes[typeof (res.header)]) {
|
||||
if (res.header && headerTypes[typeof (res.header)]) {
|
||||
headers = res.header;
|
||||
delete res.header;
|
||||
} else if (res.headers !== undefined &&
|
||||
headerTypes[typeof (res.headers)])
|
||||
{
|
||||
} else if (res.headers && headerTypes[typeof (res.headers)]) {
|
||||
headers = res.headers;
|
||||
delete res.headers;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Trent Mick. All rights reserved.
|
||||
* Copyright (c) 2015 Trent Mick. All rights reserved.
|
||||
*
|
||||
* Test the `bunyan` CLI.
|
||||
*/
|
||||
|
||||
var p = console.warn;
|
||||
var path = require('path');
|
||||
var exec = require('child_process').exec;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var _ = require('util').format;
|
||||
var vasync = require('vasync');
|
||||
|
||||
|
@ -401,11 +402,14 @@ test('robust req handling', function (t) {
|
|||
});
|
||||
|
||||
// Some past crashes from issues.
|
||||
test('should not crash on these', function (t) {
|
||||
test('should not crash on corpus/old-crashers/*.log', function (t) {
|
||||
var oldCrashers = fs.readdirSync(
|
||||
path.resolve(__dirname, 'corpus/old-crashers'))
|
||||
.filter(function (f) { return f.slice(-4) === '.log'; });
|
||||
vasync.forEachPipeline({
|
||||
inputs: ['139.log', '144.log'],
|
||||
inputs: oldCrashers,
|
||||
func: function (logName, next) {
|
||||
exec(_('%s %s/corpus/%s', BUNYAN, __dirname, logName),
|
||||
exec(_('%s %s/corpus/old-crashers/%s', BUNYAN, __dirname, logName),
|
||||
function (err, stdout, stderr) {
|
||||
next(err);
|
||||
});
|
||||
|
|
1
test/corpus/old-crashers/233.log
Normal file
1
test/corpus/old-crashers/233.log
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"server","hostname":"iZ25apt4ethZ","pid":958,"level":30,"req":{"method":"GET","url":"/ground/fetch?id=null","headers":{"host":"123.123.123.123","connection":"Keep-Alive","accept-encoding":"gzip"},"remoteAddress":"::ffff:123.123.123.123"},"res":{"headers":true,"content":{"status":0,"message":"success","messages":[]}},"msg":"Time used: 30ms","time":"2015-03-07T07:28:32.431Z","v":0}
|
1
test/corpus/old-crashers/242.log
Normal file
1
test/corpus/old-crashers/242.log
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"AKP48","module":"Server","hostname":"AKP48.akpwebdesign.com","pid":32421,"level":60,"err":{"message":"Function.prototype.apply: Arguments list has wrong type","name":"TypeError","stack":[{},{},{},{},{},{}]},"msg":"Exception caught: TypeError: Function.prototype.apply: Arguments list has wrong type","time":"2015-04-13T04:03:46.206Z","v":0}
|
1
test/corpus/old-crashers/244.log
Normal file
1
test/corpus/old-crashers/244.log
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"multichannel","hostname":"macbook-dev","pid":44973,"level":30,"res":{"statusCode":401,"header":null},"response":"{\"error\":\"InvalidCredentials\",\"description\":\"The access token provided has expired.\"}","msg":"","time":"2015-04-15T10:37:39.557Z","v":0}
|
2
test/corpus/old-crashers/README.md
Normal file
2
test/corpus/old-crashers/README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
Log lines that used to crash `bunyan`.
|
||||
Typically the file name is the bunyan issue number.
|
Loading…
Reference in a new issue