mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 09:56:22 +00:00
Refactor error handling (interim).
This commit is contained in:
parent
7765e85336
commit
a9c685c6a4
@ -28,33 +28,43 @@ Error-handling routines for HackMyResume.
|
|||||||
*/
|
*/
|
||||||
var ErrorHandler = module.exports = {
|
var ErrorHandler = module.exports = {
|
||||||
|
|
||||||
init: function( debug ) {
|
init: function( debug, assert ) {
|
||||||
this.debug = debug;
|
this.debug = debug;
|
||||||
|
this.assert = assert;
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
err: function( ex, shouldExit ) {
|
err: function( ex, shouldExit ) {
|
||||||
|
|
||||||
|
if( ex.pass )
|
||||||
|
throw ex;
|
||||||
|
|
||||||
if( ex.fluenterror ) {
|
if( ex.fluenterror ) {
|
||||||
|
|
||||||
|
// Output the error message
|
||||||
var objError = assembleError( ex );
|
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 )
|
if( objError.showStack )
|
||||||
o( chalk.red( ex.stack || ex.inner.stack ) );
|
o( chalk.red( ex.stack || ex.inner.stack ) );
|
||||||
|
|
||||||
|
// Quit if necessary
|
||||||
if( objError.quit ) {
|
if( objError.quit ) {
|
||||||
this.debug && o(
|
this.debug && o(
|
||||||
chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
|
chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
|
||||||
|
if( this.assert ) { ex.pass = true; throw ex; }
|
||||||
process.exit( ex.fluenterror );
|
process.exit( ex.fluenterror );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
o( ex );
|
o( ex );
|
||||||
var stackTrace = ex.stack || (ex.inner && ex.inner.stack);
|
var stackTrace = ex.stack || (ex.inner && ex.inner.stack);
|
||||||
if( stackTrace && this.debug )
|
if( stackTrace && this.debug )
|
||||||
o( ex.stack || ex.inner.stack );
|
o( ex.stack || ex.inner.stack );
|
||||||
|
|
||||||
// if( this.debug )
|
// if( this.debug )
|
||||||
// o( ex.stack || ex.inner.stack );
|
// o( ex.stack || ex.inner.stack );
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ Definition of the `main` function.
|
|||||||
.option('--no-color', 'Disable colors')
|
.option('--no-color', 'Disable colors')
|
||||||
.option('--color', 'Enable colors')
|
.option('--color', 'Enable colors')
|
||||||
.option('-d --debug', 'Enable diagnostics', false)
|
.option('-d --debug', 'Enable diagnostics', false)
|
||||||
|
.option('-a --assert', 'Treat warnings as errors', false)
|
||||||
.option('-v --version', 'Show the version')
|
.option('-v --version', 'Show the version')
|
||||||
.allowUnknownOption();
|
.allowUnknownOption();
|
||||||
program.jsonArgs = initInfo.options;
|
program.jsonArgs = initInfo.options;
|
||||||
@ -69,7 +70,6 @@ Definition of the `main` function.
|
|||||||
program
|
program
|
||||||
.command('validate')
|
.command('validate')
|
||||||
.arguments('<sources...>')
|
.arguments('<sources...>')
|
||||||
.option('-a --assert', 'Treat validation warnings as errors', false)
|
|
||||||
.description('Validate a resume in FRESH or JSON RESUME format.')
|
.description('Validate a resume in FRESH or JSON RESUME format.')
|
||||||
.action(function(sources) {
|
.action(function(sources) {
|
||||||
execute.call( this, sources, [], this.opts(), logMsg);
|
execute.call( this, sources, [], this.opts(), logMsg);
|
||||||
@ -217,11 +217,14 @@ Definition of the `main` function.
|
|||||||
function execute( src, dst, opts, log ) {
|
function execute( src, dst, opts, log ) {
|
||||||
|
|
||||||
loadOptions.call( this, opts, this.parent.jsonArgs );
|
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() ]();
|
var v = new HMR.verbs[ this.name() ]();
|
||||||
_out.init( _opts );
|
_out.init( _opts );
|
||||||
v.on( 'hmr:status', function() { _out.do.apply( _out, arguments ); });
|
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 );
|
v.invoke.call( v, src, dst, _opts, log );
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -250,6 +253,8 @@ Definition of the `main` function.
|
|||||||
o.silent = this.parent.silent;
|
o.silent = this.parent.silent;
|
||||||
if( this.parent.debug !== undefined && this.parent.debug !== null)
|
if( this.parent.debug !== undefined && this.parent.debug !== null)
|
||||||
o.debug = this.parent.debug;
|
o.debug = this.parent.debug;
|
||||||
|
if( this.parent.assert !== undefined && this.parent.assert !== null)
|
||||||
|
o.assert = this.parent.assert;
|
||||||
|
|
||||||
if( o.debug ) {
|
if( o.debug ) {
|
||||||
logMsg(chalk.cyan('OPTIONS:') + '\n');
|
logMsg(chalk.cyan('OPTIONS:') + '\n');
|
||||||
|
@ -71,16 +71,6 @@ Definition of the FRESHResume class.
|
|||||||
*/
|
*/
|
||||||
FreshResume.prototype.parseJSON = function( rep, opts ) {
|
FreshResume.prototype.parseJSON = function( rep, opts ) {
|
||||||
|
|
||||||
// // Convert JSON Resume to FRESH if necessary
|
|
||||||
// // TODO: Not sure if this code path is still executed. JRS resumes should
|
|
||||||
// // be loaded via JRSResume, not here.
|
|
||||||
// if( rep.basics ) {
|
|
||||||
// throw "Invalid resume conversion path";
|
|
||||||
// rep = CONVERTER.toFRESH( rep );
|
|
||||||
// rep.imp = rep.imp || { };
|
|
||||||
// rep.imp.orgFormat = 'JRS';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Now apply the resume representation onto this object
|
// Now apply the resume representation onto this object
|
||||||
extend( true, this, rep );
|
extend( true, this, rep );
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ Definition of the Verb class.
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fire the 'hmr:error' error event.
|
Handle an error condition.
|
||||||
*/
|
*/
|
||||||
err: function( errorCode, payload, hot ) {
|
err: function( errorCode, payload, hot ) {
|
||||||
payload = payload || { };
|
payload = payload || { };
|
||||||
|
@ -10,6 +10,7 @@ var chai = require('chai')
|
|||||||
, FRESHResume = require('../src/core/fresh-resume')
|
, FRESHResume = require('../src/core/fresh-resume')
|
||||||
, FCMD = require( '../src/hackmyapi')
|
, FCMD = require( '../src/hackmyapi')
|
||||||
, validator = require('is-my-json-valid')
|
, validator = require('is-my-json-valid')
|
||||||
|
, HMRMAIN = require('../src/cli/main')
|
||||||
, EXTEND = require('../src/utils/extend');
|
, EXTEND = require('../src/utils/extend');
|
||||||
|
|
||||||
chai.config.includeStack = false;
|
chai.config.includeStack = false;
|
||||||
@ -74,6 +75,9 @@ describe('Testing CLI interface', function () {
|
|||||||
function runIt() {
|
function runIt() {
|
||||||
try {
|
try {
|
||||||
var v = new FCMD.verbs[verb]();
|
var v = new FCMD.verbs[verb]();
|
||||||
|
v.on('hmr:error', function(ex) {
|
||||||
|
throw ex;
|
||||||
|
});
|
||||||
v.invoke( src, dst, opts, opts.silent ?
|
v.invoke( src, dst, opts, opts.silent ?
|
||||||
function(){} : function(msg){ msg = msg || ''; console.log(msg); } );
|
function(){} : function(msg){ msg = msg || ''; console.log(msg); } );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user