From 2f628f8564d0ddc254ade400eb9bfe8aa7adb26f Mon Sep 17 00:00:00 2001 From: hacksalot Date: Mon, 18 Jan 2016 20:06:45 -0500 Subject: [PATCH] Reconnect process exit codes. --- src/cli/main.js | 14 ++++++++------ src/verbs/analyze.js | 7 +++++-- src/verbs/build.js | 4 +++- src/verbs/convert.js | 8 ++++---- src/verbs/create.js | 3 ++- src/verbs/peek.js | 11 +++++------ src/verbs/validate.js | 5 ++++- src/verbs/verb.js | 11 +++++++++++ test/test-hmr.txt | 8 ++++---- 9 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/cli/main.js b/src/cli/main.js index 18ecf81..7cfc40f 100644 --- a/src/cli/main.js +++ b/src/cli/main.js @@ -16,7 +16,7 @@ Definition of the `main` function. , EXTEND = require('extend') , chalk = require('chalk') , PATH = require('path') - , HACKMYSTATUS = require('../core/status-codes') + , HMSTATUS = require('../core/status-codes') , HME = require('../core/event-codes') , safeLoadJSON = require('../utils/safe-json-loader') , StringUtils = require('../utils/string.js') @@ -150,14 +150,15 @@ Definition of the `main` function. // Handle invalid verbs here (a bit easier here than in commander.js)... if( o.verb && !HMR.verbs[ o.verb ] && !HMR.alias[ o.verb ] ) { - throw { fluenterror: HACKMYSTATUS.invalidCommand, shouldExit: true, + throw { fluenterror: HMSTATUS.invalidCommand, quit: true, attempted: o.orgVerb }; } // Override the .missingArgument behavior Command.prototype.missingArgument = function(name) { - if( this.name() !== 'new' ) - throw { fluenterror: HACKMYSTATUS.resumeNotFound }; + if( this.name() !== 'new' ) { + throw { fluenterror: HMSTATUS.resumeNotFound, quit: true }; + } }; // Override the .helpInformation behavior @@ -243,7 +244,8 @@ Definition of the `main` function. hand.err.apply( hand, arguments ); }); v.invoke.call( v, src, dst, _opts, log ); - + if( v.errorCode ) + process.exit(v.errorCode); } @@ -293,7 +295,7 @@ Definition of the `main` function. var params = this.parent.args.filter(function(j) { return String.is(j); }); if( params.length === 0 ) - throw { fluenterror: HACKMYSTATUS.resumeNotFound }; + throw { fluenterror: HMSTATUS.resumeNotFound, quit: true }; // Find the TO keyword, if any var splitAt = _.findIndex( params, function(p) { diff --git a/src/verbs/analyze.js b/src/verbs/analyze.js index 0373a72..94e7336 100644 --- a/src/verbs/analyze.js +++ b/src/verbs/analyze.js @@ -42,7 +42,7 @@ Implementation of the 'analyze' verb for HackMyResume. */ function analyze( sources, dst, opts ) { if( !sources || !sources.length ) - throw { fluenterror: HMSTATUS.resumeNotFound }; + throw { fluenterror: HMSTATUS.resumeNotFound, quit: true }; var nlzrs = _loadInspectors(); @@ -50,7 +50,10 @@ Implementation of the 'analyze' verb for HackMyResume. var result = ResumeFactory.loadOne( src, { format: 'FRESH', objectify: true }, this); - result.fluenterror || _analyze.call(this, result, nlzrs, opts ); + if( result.fluenterror ) + this.setError( result.fluenterror, result ); + else + _analyze.call(this, result, nlzrs, opts ); }, this); } diff --git a/src/verbs/build.js b/src/verbs/build.js index 0e40cde..fbbba2a 100644 --- a/src/verbs/build.js +++ b/src/verbs/build.js @@ -62,7 +62,9 @@ Implementation of the 'build' verb for HackMyResume. */ function build( src, dst, opts ) { - if( !src || !src.length ) { this.err( HMSTATUS.resumeNotFound ); } + if( !src || !src.length ) { + this.err( HMSTATUS.resumeNotFound, { quit: true } ); + } prep( src, dst, opts ); diff --git a/src/verbs/convert.js b/src/verbs/convert.js index f715298..6ceb803 100644 --- a/src/verbs/convert.js +++ b/src/verbs/convert.js @@ -40,20 +40,20 @@ Implementation of the 'convert' verb for HackMyResume. function convert( srcs, dst, opts ) { // Housekeeping - if( !srcs || !srcs.length ) { throw { fluenterror: 6 }; } + if( !srcs || !srcs.length ) { throw { fluenterror: 6, quit: true }; } if( !dst || !dst.length ) { if( srcs.length === 1 ) { - throw { fluenterror: HMSTATUS.inputOutputParity }; + throw { fluenterror: HMSTATUS.inputOutputParity, quit: true }; } else if( srcs.length === 2 ) { dst = dst || []; dst.push( srcs.pop() ); } else { - throw { fluenterror: HMSTATUS.inputOutputParity }; + throw { fluenterror: HMSTATUS.inputOutputParity, quit: true }; } } if(srcs && dst && srcs.length && dst.length && srcs.length !== dst.length){ - throw { fluenterror: HMSTATUS.inputOutputParity }; + throw { fluenterror: HMSTATUS.inputOutputParity, quit: true }; } // Load source resumes diff --git a/src/verbs/create.js b/src/verbs/create.js index 1c06fb5..3834abd 100644 --- a/src/verbs/create.js +++ b/src/verbs/create.js @@ -41,7 +41,8 @@ Implementation of the 'create' verb for HackMyResume. */ function create( src, dst, opts ) { - if(!src || !src.length) throw {fluenterror: HMSTATUS.createNameMissing}; + if( !src || !src.length ) + throw { fluenterror: HMSTATUS.createNameMissing, quit: true }; _.each( src, function( t ) { var safeFmt = opts.format.toUpperCase(); diff --git a/src/verbs/peek.js b/src/verbs/peek.js index 32ead87..992cf16 100644 --- a/src/verbs/peek.js +++ b/src/verbs/peek.js @@ -67,13 +67,12 @@ Implementation of the 'peek' verb for HackMyResume. // safeLoadJSON can only return a READ error or a PARSE error if( obj.ex ) { - if( obj.ex.operation === 'parse' ) - this.err( HMSTATUS.parseError, obj.ex ); - else { + var errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError; + if( errCode === HMSTATUS.readError ) obj.ex.quiet = true; - this.err( HMSTATUS.readError, obj.ex ); - } - } + this.setError( errCode, obj.ex ); + this.err( errCode, obj.ex ); + } }, this); diff --git a/src/verbs/validate.js b/src/verbs/validate.js index 651ab20..6603d22 100644 --- a/src/verbs/validate.js +++ b/src/verbs/validate.js @@ -38,7 +38,9 @@ Implementation of the 'validate' verb for HackMyResume. */ function validate( sources, unused, opts ) { - if( !sources || !sources.length ) { throw { fluenterror: 6 }; } + if( !sources || !sources.length ) + throw { fluenterror: HMSTATUS.resumeNotFoundAlt, quit: true }; + var isValid = true; var validator = require('is-my-json-valid'); @@ -61,6 +63,7 @@ Implementation of the 'validate' verb for HackMyResume. // If there was an error reading the resume if( src.fluenterror ) { if( opts.assert ) throw src; + this.setError( src.fluenterror, src ); return ret; } diff --git a/src/verbs/verb.js b/src/verbs/verb.js index cbe3af9..4e19824 100644 --- a/src/verbs/verb.js +++ b/src/verbs/verb.js @@ -78,8 +78,19 @@ Definition of the Verb class. payload.sub = subEvent; this.fire('status', payload); return true; + }, + + + /** + Associate error info with the invocation. + */ + setError: function( code, obj ) { + this.errorCode = code; + this.errorObj = obj; } + + }); }()); diff --git a/test/test-hmr.txt b/test/test-hmr.txt index 21981b2..0925773 100644 --- a/test/test-hmr.txt +++ b/test/test-hmr.txt @@ -1,8 +1,8 @@ 0| -4|--help -4|-h -4|--debug -4|-d +0|--help +0|-h +0|--debug +0|-d 5|notacommand 3|build 14|build doesnt-exist.json