improve 'the bunyan cli has crashed' messaging

This commit is contained in:
Trent Mick 2015-01-16 21:08:42 -08:00
parent d77f824723
commit d412ecef12
2 changed files with 11 additions and 11 deletions

View file

@ -8,7 +8,8 @@ Known issues:
## bunyan 1.2.5 (not yet released) ## bunyan 1.2.5 (not yet released)
(nothing yet) - [issue #205] Fix the "The Bunyan CLI crashed!" checking to properly warn of
the common failure case when `-c CONDITION` is being used.
## bunyan 1.2.4 ## bunyan 1.2.4

View file

@ -92,8 +92,8 @@ var child = null;
// Whether ANSI codes are being used. Used for signal-handling. // Whether ANSI codes are being used. Used for signal-handling.
var usingAnsiCodes = false; var usingAnsiCodes = false;
// Global ref to options used only by 'uncaughtException' handler. // Used to tell the 'uncaughtException' handler that '-c CODE' is being used.
var gOptsForUncaughtException; var gUsingConditionOpts = false;
// Pager child process, and output stream to which to write. // Pager child process, and output stream to which to write.
var pager = null; var pager = null;
@ -400,7 +400,6 @@ function parseArgv(argv) {
outputMode: OM_LONG, outputMode: OM_LONG,
jsonIndent: 2, jsonIndent: 2,
level: null, level: null,
conditions: null,
strict: false, strict: false,
pids: null, pids: null,
pidsType: null pidsType: null
@ -529,6 +528,7 @@ function parseArgv(argv) {
break; break;
case '-c': case '-c':
case '--condition': case '--condition':
gUsingConditionOpts = true;
var condition = args.shift(); var condition = args.shift();
if (Boolean(process.env.BUNYAN_EXEC && if (Boolean(process.env.BUNYAN_EXEC &&
process.env.BUNYAN_EXEC === 'vm')) process.env.BUNYAN_EXEC === 'vm'))
@ -1425,13 +1425,13 @@ process.on('uncaughtException', function (err) {
var title = encodeURIComponent(format( var title = encodeURIComponent(format(
'Bunyan %s crashed: %s', getVersion(), String(err))); 'Bunyan %s crashed: %s', getVersion(), String(err)));
var e = console.error; var e = console.error;
e('* * *'); e('```');
e('* The Bunyan CLI crashed!'); e('* The Bunyan CLI crashed!');
e('*'); e('*');
if (err.name === 'ReferenceError' && gOptsForUncaughtException.conditions) { if (err.name === 'ReferenceError' && gUsingConditionOpts) {
e('* A "ReferenceError" is often the result of given'); e('* This crash was due to a "ReferenceError", which is often the result of given');
e('* `-c CONDITION` code that doesn\'t guard against undefined'); e('* `-c CONDITION` code that doesn\'t guard against undefined values. If that is');
e('* values. If that is not the problem:'); e('* not the problem:');
e('*'); e('*');
} }
e('* Please report this issue and include the details below:'); e('* Please report this issue and include the details below:');
@ -1446,7 +1446,7 @@ process.on('uncaughtException', function (err) {
e('* log line: %j', currLine); e('* log line: %j', currLine);
e('* stack:'); e('* stack:');
e(_indent(err.stack)); e(_indent(err.stack));
e('* * *'); e('```');
process.exit(1); process.exit(1);
}); });
@ -1458,7 +1458,6 @@ function main(argv) {
warn('bunyan: error: %s', e.message); warn('bunyan: error: %s', e.message);
return drainStdoutAndExit(1); return drainStdoutAndExit(1);
} }
gOptsForUncaughtException = opts; // intentionally global
if (opts.help) { if (opts.help) {
printHelp(); printHelp();
return; return;