Skip to content

Commit

Permalink
Add try / catch for non standard lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Neamar committed Nov 25, 2014
1 parent f4caf15 commit 3bce56f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bin/bunyan
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,16 @@ function emitRecord(rec, line, opts, stylize) {
rec._cS = stylize.start;
// Shortcut for "colorEnd"
rec._cE = stylize.end;
emit(opts.template ? opts.template(rec) : 'No template defined. Use --template.' +'\n');

var out;
try {
out = opts.template ? opts.template(rec) : 'No template defined. Use --template.';
}
catch(e) {
// Unprocessable line, display default
out = JSON.stringify(rec, null, opts.jsonIndent);
}
emit(out + '\n');
break;
default:
throw new Error('unknown output mode: '+opts.outputMode);
Expand Down

0 comments on commit 3bce56f

Please sign in to comment.