From 337d7d977c1b1cb6beaecbd495efd27b1a30ce1a Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 10 Oct 2012 11:28:03 -0700 Subject: [PATCH] Add an uncaughtException handler to request a ticket and details. Looks like this: * * * * The Bunyan CLI crashed! Please report this issue: * * https://github.com/trentm/node-bunyan/issues/new * * and include the following Bunyan details the log file * (or section of log file) on which the Bunyan CLI crashed. * * * * node version: v0.8.9 * bunyan version: 0.14.2 * argv: [ 'node', '/Users/trentm/tm/node-bunyan-0.x/bin/bunyan' ] * stack: * TypeError: Object.keys called on non-object * at Function.keys (native) * at emitRecord (/Users/trentm/tm/node-bunyan-0.x/bin/bunyan:718:14) * at handleLogLine (/Users/trentm/tm/node-bunyan-0.x/bin/bunyan:507:12) * at Socket. (/Users/trentm/tm/node-bunyan-0.x/bin/bunyan:856:7) * at Socket.EventEmitter.emit (events.js:88:17) * at Pipe.onread (net.js:391:31) * * * --- bin/bunyan | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bin/bunyan b/bin/bunyan index 7ec324c..f1bd398 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -959,6 +959,32 @@ function asyncForEach(arr, iterator, callback) { //---- mainline +process.on('uncaughtException', function (err) { + function indent(s) { + var lines = s.split(/\r?\n/); + for (var i = 0; i < lines.length; i++) { + lines[i] = '* ' + lines[i]; + } + return lines.join('\n'); + } + + console.error('* * *'); + console.error('* The Bunyan CLI crashed! Please report this issue:'); + console.error('*'); + console.error('* https://github.com/trentm/node-bunyan/issues/new'); + console.error('*'); + console.error('* and include the following Bunyan details the log file'); + console.error('* (or section of log file) on which the Bunyan CLI crashed.'); + console.error('* * *'); + console.error('* node version:', process.version); + console.error('* bunyan version:', getVersion()); + console.error('* argv:', process.argv); + console.error('* stack:'); + console.error(indent(err.stack)); + console.error('* * *'); + process.exit(1); +}); + function main(argv) { var opts; try {