From 5bf4bda6de8c1f42ff1e90c817d02c25330d4980 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Wed, 3 Feb 2016 20:08:17 -0500 Subject: [PATCH] Fix PEEK command. --- dist/cli/main.js | 1 - dist/cli/out.js | 2 +- dist/verbs/peek.js | 7 +++---- src/cli/main.coffee | 1 - src/cli/out.coffee | 6 +++--- src/verbs/peek.coffee | 15 +++++++++------ test/scripts/test-hmr.txt | 19 +++++++++++++------ test/scripts/test-themes.js | 10 +++++++++- 8 files changed, 38 insertions(+), 23 deletions(-) diff --git a/dist/cli/main.js b/dist/cli/main.js index b511831..faea6f6 100644 --- a/dist/cli/main.js +++ b/dist/cli/main.js @@ -236,7 +236,6 @@ Definition of the `main` function. finalErrorCode = -1; if (err) { finalErrorCode = err.fluenterror ? err.fluenterror : err; - console.log(err.stack); } if (_opts.debug) { msgs = require('./msg').errors; diff --git a/dist/cli/out.js b/dist/cli/out.js index 0fd68a6..33512c2 100644 --- a/dist/cli/out.js +++ b/dist/cli/out.js @@ -147,7 +147,7 @@ Output routines for HackMyResume. } else { L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file); } - if (evt.target !== void 0) { + if (evt.target !== void 0 && !evt.error) { return console.dir(evt.target, { depth: null, colors: true diff --git a/dist/verbs/peek.js b/dist/verbs/peek.js index e1ab341..8445d37 100644 --- a/dist/verbs/peek.js +++ b/dist/verbs/peek.js @@ -52,8 +52,7 @@ Implementation of the 'peek' verb for HackMyResume. } tgt = _peekOne.call(this, t, objPath); if (tgt.error) { - tgt.quit = opts.assert; - this.err(tgt.fluenterror, tgt); + this.setError(tgt.error.fluenterror, tgt.error); } return tgt; }, this); @@ -97,8 +96,8 @@ Implementation of the 'peek' verb for HackMyResume. error: pkgError }); return { - val: tgt, - errpr: pkgError + val: obj.ex ? void 0 : tgt, + error: pkgError }; }; diff --git a/src/cli/main.coffee b/src/cli/main.coffee index 59e7d43..52318a2 100644 --- a/src/cli/main.coffee +++ b/src/cli/main.coffee @@ -271,7 +271,6 @@ executeFail = (err) -> finalErrorCode = -1 if err finalErrorCode = if err.fluenterror then err.fluenterror else err - console.log err.stack if _opts.debug msgs = require('./msg').errors; logMsg printf M2C( msgs.exiting.msg, 'cyan' ), finalErrorCode diff --git a/src/cli/out.coffee b/src/cli/out.coffee index 361f1c0..98a7103 100644 --- a/src/cli/out.coffee +++ b/src/cli/out.coffee @@ -165,12 +165,12 @@ module.exports = class OutputHandler L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file) # If the key was present, print it - if evt.target != undefined + if evt.target != undefined and !evt.error console.dir( evt.target, { depth: null, colors: true } ) # If the key was not present, but no error occurred, print it else if !evt.error - L(M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file); + L M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file else if evt.error - L( chalk.red( evt.error.inner.inner )); + L chalk.red( evt.error.inner.inner ) diff --git a/src/verbs/peek.coffee b/src/verbs/peek.coffee index a0bb51e..8072dd2 100644 --- a/src/verbs/peek.coffee +++ b/src/verbs/peek.coffee @@ -31,11 +31,14 @@ _peek = ( src, dst, opts ) -> objPath = (dst && dst[0]) || '' results = _.map src, ( t ) -> + return { } if opts.assert and @hasError() + tgt = _peekOne.call @, t, objPath if tgt.error - tgt.quit = opts.assert - @err tgt.fluenterror, tgt + @setError tgt.error.fluenterror, tgt.error + #tgt.error.quit = opts.assert + #@err tgt.error.fluenterror, tgt.error tgt , @ @@ -56,9 +59,9 @@ _peekOne = ( t, objPath ) -> obj = safeLoadJSON t # Fetch the requested object path (or the entire file) - tgt = null; + tgt = null if !obj.ex - tgt = if objPath then __.get obj.json, objPath else obj.json; + tgt = if objPath then __.get obj.json, objPath else obj.json ## safeLoadJSON can only return a READ error or a PARSE error pkgError = null @@ -68,7 +71,6 @@ _peekOne = ( t, objPath ) -> obj.ex.quiet = true pkgError = fluenterror: errCode, inner: obj.ex - # Fire the 'afterPeek' event with collected info @stat HMEVENT.afterPeek, file: t @@ -76,4 +78,5 @@ _peekOne = ( t, objPath ) -> target: if obj.ex then undefined else tgt error: pkgError - val: tgt, errpr: pkgError + val: if obj.ex then undefined else tgt + error: pkgError diff --git a/test/scripts/test-hmr.txt b/test/scripts/test-hmr.txt index bdf2c82..fb88bef 100644 --- a/test/scripts/test-hmr.txt +++ b/test/scripts/test-hmr.txt @@ -19,16 +19,23 @@ 3|peek 14|peek doesnt-exist.json 14|peek doesnt-exist.json not.a.path +15|peek node_modules/fresh-test-resumes/src/fresh/johnny-trouble.broken.json 0|peek test/resumes/jrs-0.0.0/richard-hendriks.json work[0] 0|peek node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json employment.history[1] 0|peek node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json skills.sets 3|build -0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.html -0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.pdf -0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.md -0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.txt -0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.yml -0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.json +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.all +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.html +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.pdf +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.md +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.txt +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.yml +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.json +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.all --theme modern +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.all --theme compact +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.all --theme positive +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.all --theme basis +0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json TO test/sandbox/cli-test/jane/resume.all --theme awesome 14|build doesnt-exist.json 14|build doesnt-exist.json -t not-a-theme 14|build doesnt-exist.json -t node_modules/not-a-theme diff --git a/test/scripts/test-themes.js b/test/scripts/test-themes.js index c7dc95b..50b04dc 100644 --- a/test/scripts/test-themes.js +++ b/test/scripts/test-themes.js @@ -37,7 +37,15 @@ function genThemes( title, src, fmt ) { }; try { var v = new HMR.verbs.build(); - v.invoke( src, dst, opts ); + var p = v.invoke( src, dst, opts ); + p.then( + function(obj){ + + }, + function(obj){ + throw obj; + } + ); } catch(ex) { console.error( ex );