1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-10 07:47:07 +01:00

Refactor error handling (interim).

This commit is contained in:
hacksalot
2016-01-14 11:47:05 -05:00
parent 7765e85336
commit a9c685c6a4
5 changed files with 27 additions and 18 deletions

View File

@ -28,33 +28,43 @@ Error-handling routines for HackMyResume.
*/
var ErrorHandler = module.exports = {
init: function( debug ) {
init: function( debug, assert ) {
this.debug = debug;
this.assert = assert;
return this;
},
err: function( ex, shouldExit ) {
if( ex.pass )
throw ex;
if( ex.fluenterror ) {
// Output the error message
var objError = assembleError( ex );
o( this[ 'format' + (objError.warning ? 'Warning' : 'Error')]( objError.msg ) );
o( this[ 'format' + (objError.warning ? 'Warning' : 'Error')](
objError.msg
));
// Output the stack (sometimes)
if( objError.showStack )
o( chalk.red( ex.stack || ex.inner.stack ) );
// Quit if necessary
if( objError.quit ) {
this.debug && o(
chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
if( this.assert ) { ex.pass = true; throw ex; }
process.exit( ex.fluenterror );
}
}
else {
o( ex );
var stackTrace = ex.stack || (ex.inner && ex.inner.stack);
if( stackTrace && this.debug )
o( ex.stack || ex.inner.stack );
// if( this.debug )
// o( ex.stack || ex.inner.stack );
}

View File

@ -50,6 +50,7 @@ Definition of the `main` function.
.option('--no-color', 'Disable colors')
.option('--color', 'Enable colors')
.option('-d --debug', 'Enable diagnostics', false)
.option('-a --assert', 'Treat warnings as errors', false)
.option('-v --version', 'Show the version')
.allowUnknownOption();
program.jsonArgs = initInfo.options;
@ -69,7 +70,6 @@ Definition of the `main` function.
program
.command('validate')
.arguments('<sources...>')
.option('-a --assert', 'Treat validation warnings as errors', false)
.description('Validate a resume in FRESH or JSON RESUME format.')
.action(function(sources) {
execute.call( this, sources, [], this.opts(), logMsg);
@ -217,11 +217,14 @@ Definition of the `main` function.
function execute( src, dst, opts, log ) {
loadOptions.call( this, opts, this.parent.jsonArgs );
var hand = require( './error-handler' ).init( _opts.debug );
var hand = require( './error-handler' );
hand.init( _opts.debug, _opts.assert );
var v = new HMR.verbs[ this.name() ]();
_out.init( _opts );
v.on( 'hmr:status', function() { _out.do.apply( _out, arguments ); });
v.on( 'hmr:error', function() { hand.err.apply( hand, arguments ); });
v.on( 'hmr:error', function() {
hand.err.apply( hand, arguments );
});
v.invoke.call( v, src, dst, _opts, log );
}
@ -250,6 +253,8 @@ Definition of the `main` function.
o.silent = this.parent.silent;
if( this.parent.debug !== undefined && this.parent.debug !== null)
o.debug = this.parent.debug;
if( this.parent.assert !== undefined && this.parent.assert !== null)
o.assert = this.parent.assert;
if( o.debug ) {
logMsg(chalk.cyan('OPTIONS:') + '\n');