From 9fdfd1b5a6b2c2b50eb170778e6cd11e37d4d67a Mon Sep 17 00:00:00 2001 From: hacksalot Date: Fri, 8 Jan 2016 16:08:33 -0500 Subject: [PATCH] Add baseline support for -d or --debug flag. For now, -d just force-emits the stack when there is one. In the future, it can trigger more detailed logging info. --- package.json | 2 +- src/core/error-handler.js | 12 ++++++++---- src/generators/html-pdf-cli-generator.js | 4 ++-- src/index.js | 21 ++++++++++++--------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 3af577c..d8efe8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hackmyresume", - "version": "1.5.0", + "version": "1.5.1", "description": "Generate polished résumés and CVs in HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML, YAML, smoke signal, and carrier pigeon.", "repository": { "type": "git", diff --git a/src/core/error-handler.js b/src/core/error-handler.js index e50b20b..e61120b 100644 --- a/src/core/error-handler.js +++ b/src/core/error-handler.js @@ -3,7 +3,7 @@ Error-handling routines for HackMyResume. @module error-handler.js @license MIT. See LICENSE.md for details. */ - +// TODO: Logging library (function() { @@ -26,7 +26,9 @@ Error-handling routines for HackMyResume. */ var ErrorHandler = module.exports = { - + init: function( debug ) { + this.debug = debug; + }, err: function( ex, shouldExit ) { @@ -62,8 +64,10 @@ Error-handling routines for HackMyResume. log( msg.toString() ) : log( chalk.red.bold('ERROR: ' + msg.toString()) ); - // Usually emit the stack - ( showStack && ex.code !== 'ENOENT' ) && log( chalk.gray(ex.stack) ); + // Selectively show the stack trace + if( (ex.stack || (ex.inner && ex.inner.stack)) && + ((showStack && ex.code !== 'ENOENT' ) || (this.debug) )) + log( chalk.red( ex.stack || ex.stack.inner ) ); // Let the error code be the process's return code. ( shouldExit || ex.shouldExit ) && process.exit( exitCode ); diff --git a/src/generators/html-pdf-cli-generator.js b/src/generators/html-pdf-cli-generator.js index 8158806..176ac2b 100644 --- a/src/generators/html-pdf-cli-generator.js +++ b/src/generators/html-pdf-cli-generator.js @@ -47,8 +47,8 @@ Definition of the HtmlPdfCLIGenerator class. // { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', ... } // { [Error: ENOENT] } throw ( ex.inner && ex.inner.code === 'ENOENT' ) ? - { fluenterror: this.codes.notOnPath, engine: ex.cmd } : - { fluenterror: this.codes.pdfGeneration, inner: ex.inner }; + { fluenterror: this.codes.notOnPath, engine: ex.cmd, stack: ex.inner.stack } : + { fluenterror: this.codes.pdfGeneration, inner: ex.inner, stack: ex.inner.stack }; } } diff --git a/src/index.js b/src/index.js index b2c2e64..d8a2ee5 100644 --- a/src/index.js +++ b/src/index.js @@ -49,7 +49,8 @@ function main() { .option('-o --opts ', 'Path to a .hackmyrc options file') .option('-s --silent', 'Run in silent mode') .option('--no-color', 'Disable colors') - .option('--color', 'Enable colors'); + .option('--color', 'Enable colors') + .option('-d --debug', 'Enable diagnostics', false); //.usage('COMMAND [TO ]'); // Create the NEW command @@ -172,6 +173,7 @@ Invoke a HackMyResume verb. */ function execVerb( src, dst, opts, log ) { loadOptions.call( this, opts ); + require('./core/error-handler').init( _opts.debug ); HMR.verbs[ this.name() ].call( null, src, dst, _opts, log ); } @@ -180,23 +182,24 @@ function execVerb( src, dst, opts, log ) { /** Initialize HackMyResume options. */ -function loadOptions( opts ) { +function loadOptions( o ) { - opts.opts = this.parent.opts; + o.opts = this.parent.opts; // Load the specified options file (if any) and apply options - if( opts.opts && String.is( opts.opts )) { - var json = safeLoadJSON( PATH.relative( process.cwd(), opts.opts ) ); - json && ( opts = EXTEND( true, opts, json ) ); + if( o.opts && String.is( o.opts )) { + var json = safeLoadJSON( PATH.relative( process.cwd(), o.opts ) ); + json && ( o = EXTEND( true, o, json ) ); if( !json ) { throw safeLoadJSON.error; } } // Merge in command-line options - opts = EXTEND( true, opts, this.opts() ); - opts.silent = this.parent.silent; - _opts = opts; + o = EXTEND( true, o, this.opts() ); + o.silent = this.parent.silent; + o.debug = this.parent.debug; + _opts = o; }