From 6208e87ecaf8de2ae44b828f009f66a3ec4f7c1e Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 25 Nov 2013 23:46:30 -0800 Subject: [PATCH] #111 Fix a crash when attempting to use `bunyan -p` on a platform without dtrace. Also fix exit status if the spawned dtrace exits non-zero. --- CHANGES.md | 3 +++ bin/bunyan | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 484b472..79b00ef 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,9 @@ Known issues: ## bunyan 0.22.1 (not yet released) +- #111 Fix a crash when attempting to use `bunyan -p` on a platform without + dtrace. + - #101 Fix a crash in `bunyan` rendering a record with unexpected "res.headers". diff --git a/bin/bunyan b/bin/bunyan index ccff62a..01693b1 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -1129,6 +1129,15 @@ function processPids(opts, stylize, callback) { // Share the stderr handle to have error output come // straight through. Only supported in v0.8+. {stdio: ['pipe', 'pipe', process.stderr]}); + dtrace.on('error', function (e) { + if (e.syscall === 'spawn' && e.errno === 'ENOENT') { + console.error('bunyan: error: could not spawn "dtrace" ' + + '("bunyan -p" is only supported on platforms with dtrace)'); + } else { + console.error('bunyan: error: unexpected dtrace error: %s', e); + } + callback(1); + }) child = dtrace; // intentionally global function finish(code) { @@ -1136,7 +1145,7 @@ function processPids(opts, stylize, callback) { handleLogLine(null, leftover, opts, stylize); leftover = ''; } - callback(returnCode); + callback(code); } dtrace.stdout.setEncoding('utf8'); @@ -1350,6 +1359,7 @@ process.on('uncaughtException', function (err) { e('* https://github.com/trentm/node-bunyan/issues/new?title=%s', title); e('*'); e('* * *'); + e('* platform:', process.platform); e('* node version:', process.version); e('* bunyan version:', getVersion()); e('* argv: %j', process.argv);