From fd39cc9fd929f25fdadfaff47b55d0557ae591a9 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Mon, 1 Feb 2016 22:56:08 -0500 Subject: [PATCH] Adjust error handling / tests. --- dist/cli/main.js | 9 +++------ dist/verbs/create.js | 2 +- dist/verbs/validate.js | 1 - dist/verbs/verb.js | 3 ++- src/cli/main.coffee | 10 ++++++++-- src/verbs/create.coffee | 2 +- src/verbs/validate.coffee | 1 - src/verbs/verb.coffee | 3 ++- test/scripts/test-api.js | 22 +++++++++++++++------- test/scripts/test-hmr.txt | 4 ++-- 10 files changed, 34 insertions(+), 23 deletions(-) diff --git a/dist/cli/main.js b/dist/cli/main.js index 2f390ce..40a3da1 100644 --- a/dist/cli/main.js +++ b/dist/cli/main.js @@ -119,12 +119,9 @@ Definition of the `main` function. }, true); } Command.prototype.missingArgument = function(name) { - if (this.name() !== 'new') { - throw { - fluenterror: HMSTATUS.resumeNotFound, - quit: true - }; - } + _err.err({ + fluenterror: this.name() !== 'new' ? HMSTATUS.resumeNotFound : HMSTATUS.createNameMissing + }, true); }; Command.prototype.helpInformation = function() { var manPage; diff --git a/dist/verbs/create.js b/dist/verbs/create.js index d27b030..43a492d 100644 --- a/dist/verbs/create.js +++ b/dist/verbs/create.js @@ -52,7 +52,7 @@ Implementation of the 'create' verb for HackMyResume. return r; }, this); if (this.hasError() && !opts.assert) { - this.reject(results); + this.reject(this.errorCode); } else if (!this.hasError()) { this.resolve(results); } diff --git a/dist/verbs/validate.js b/dist/verbs/validate.js index 488ae94..ce33673 100644 --- a/dist/verbs/validate.js +++ b/dist/verbs/validate.js @@ -58,7 +58,6 @@ Implementation of the 'validate' verb for HackMyResume. } r = _validateOne.call(this, t, validator, schemas); if (r.fluenterror) { - console.log(r); r.quit = opts.assert; this.err(r.fluenterror, r); } diff --git a/dist/verbs/verb.js b/dist/verbs/verb.js index dda2b0b..95332f6 100644 --- a/dist/verbs/verb.js +++ b/dist/verbs/verb.js @@ -66,7 +66,8 @@ Definition of the Verb class. payload["throw"] = hot; this.setError(errorCode, payload); if (payload.quit) { - this.reject(payload); + console.log(payload); + this.reject(errorCode); } this.fire('error', payload); if (hot) { diff --git a/src/cli/main.coffee b/src/cli/main.coffee index d8a7606..ff81492 100644 --- a/src/cli/main.coffee +++ b/src/cli/main.coffee @@ -157,8 +157,14 @@ initialize = ( ar, exitCallback ) -> # Override the .missingArgument behavior Command.prototype.missingArgument = (name) -> - if this.name() != 'new' - throw { fluenterror: HMSTATUS.resumeNotFound, quit: true } + _err.err + fluenterror: + if this.name() != 'new' + then HMSTATUS.resumeNotFound + else HMSTATUS.createNameMissing + , true + return + # Override the .helpInformation behavior Command.prototype.helpInformation = -> diff --git a/src/verbs/create.coffee b/src/verbs/create.coffee index 22b0c2a..0f659db 100644 --- a/src/verbs/create.coffee +++ b/src/verbs/create.coffee @@ -39,7 +39,7 @@ _create = ( src, dst, opts ) -> , @ if @hasError() and !opts.assert - @reject results + @reject @errorCode else if !@hasError() @resolve results results diff --git a/src/verbs/validate.coffee b/src/verbs/validate.coffee index 370b161..b14a993 100644 --- a/src/verbs/validate.coffee +++ b/src/verbs/validate.coffee @@ -43,7 +43,6 @@ _validate = (sources, unused, opts) -> return { } if @hasError() and opts.assert r = _validateOne.call @, t, validator, schemas if r.fluenterror - console.log r r.quit = opts.assert @err r.fluenterror, r r diff --git a/src/verbs/verb.coffee b/src/verbs/verb.coffee index 85e5272..5e39b1f 100644 --- a/src/verbs/verb.coffee +++ b/src/verbs/verb.coffee @@ -64,7 +64,8 @@ Verb = module.exports = Class.extend payload.throw = hot @setError errorCode, payload if payload.quit - @reject payload + console.log payload + @reject errorCode @fire 'error', payload if hot throw payload diff --git a/test/scripts/test-api.js b/test/scripts/test-api.js index 85de97c..cf7bb03 100644 --- a/test/scripts/test-api.js +++ b/test/scripts/test-api.js @@ -63,7 +63,7 @@ var tests = [ ' (multiple JRS resumes)' ], - [ '!new', + [ 'new', [], [], opts, @@ -152,7 +152,7 @@ var tests = [ } ], - [ '!build', + [ 'build', [ ft + 'jane-fullstacker.json'], [ sb + 'shouldnt-exist.pdf' ], EXTEND(true, {}, opts, { theme: 'awesome' }), @@ -172,16 +172,24 @@ describe('Testing API interface', function () { shouldSucceed = false; } - it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () { + it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' NOT THROW' : ' THROW') + msg, function () { function runIt() { try { var v = new FCMD.verbs[verb](); v.on('hmr:error', function(ex) { throw ex; }); - var r = v.invoke( src, dst, opts ); - if( fnTest ) - if( !fnTest( r.sheet ) ) - throw "Test: Unexpected API result."; + var prom = v.invoke( src, dst, opts ); + prom.then( + function( obj ) { + if( fnTest ) + if( !fnTest( obj ) ) + throw "Test: Unexpected API result."; + }, + function( error ) { + throw error; + } + ); + } catch(ex) { console.error(ex); diff --git a/test/scripts/test-hmr.txt b/test/scripts/test-hmr.txt index 55d562b..7debe24 100644 --- a/test/scripts/test-hmr.txt +++ b/test/scripts/test-hmr.txt @@ -1,8 +1,8 @@ 4| 0|--help 0|-h -0|--debug -0|-d +4|--debug +4|-d 5|notacommand 8|new 0|new test/sandbox/cli-test/new-empty-resume.auto.json