diff --git a/dist/cli/out.js b/dist/cli/out.js index ff0ae6f..0fd68a6 100644 --- a/dist/cli/out.js +++ b/dist/cli/out.js @@ -154,6 +154,8 @@ Output routines for HackMyResume. }); } else if (!evt.error) { return L(M2C(this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file); + } else if (evt.error) { + return L(chalk.red(evt.error.inner.inner)); } } }; diff --git a/dist/verbs/peek.js b/dist/verbs/peek.js index aae8215..e1ab341 100644 --- a/dist/verbs/peek.js +++ b/dist/verbs/peek.js @@ -51,10 +51,11 @@ Implementation of the 'peek' verb for HackMyResume. return {}; } tgt = _peekOne.call(this, t, objPath); - if (tgt.fluenterror) { + if (tgt.error) { tgt.quit = opts.assert; - return this.err(tgt.fluenterror, tgt); + this.err(tgt.fluenterror, tgt); } + return tgt; }, this); if (this.hasError() && !opts.assert) { this.reject(this.errorCode); @@ -68,7 +69,7 @@ Implementation of the 'peek' verb for HackMyResume. /** Peek at a single resume, resume section, or resume field. */ _peekOne = function(t, objPath) { - var errCode, obj, tgt; + var errCode, obj, pkgError, tgt; this.stat(HMEVENT.beforePeek, { file: t, target: objPath @@ -78,23 +79,27 @@ Implementation of the 'peek' verb for HackMyResume. if (!obj.ex) { tgt = objPath ? __.get(obj.json, objPath) : obj.json; } - this.stat(HMEVENT.afterPeek, { - file: t, - requested: objPath, - target: tgt, - error: obj.ex - }); + pkgError = null; if (obj.ex) { errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError; if (errCode === HMSTATUS.readError) { obj.ex.quiet = true; } - return { + pkgError = { fluenterror: errCode, inner: obj.ex }; } - return tgt; + this.stat(HMEVENT.afterPeek, { + file: t, + requested: objPath, + target: obj.ex ? void 0 : tgt, + error: pkgError + }); + return { + val: tgt, + errpr: pkgError + }; }; }).call(this); diff --git a/src/cli/out.coffee b/src/cli/out.coffee index 9eeb0e7..361f1c0 100644 --- a/src/cli/out.coffee +++ b/src/cli/out.coffee @@ -157,12 +157,20 @@ module.exports = class OutputHandler when HME.afterPeek sty = if evt.error then 'red' else ( if evt.target != undefined then 'green' else 'yellow' ) + + # "Peeking at 'someKey' in 'someFile'." if evt.requested L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file) else L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file) + # If the key was present, print it if evt.target != undefined 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); + + else if evt.error + L( chalk.red( evt.error.inner.inner )); diff --git a/src/verbs/peek.coffee b/src/verbs/peek.coffee index 6e2aca6..a0bb51e 100644 --- a/src/verbs/peek.coffee +++ b/src/verbs/peek.coffee @@ -33,9 +33,10 @@ _peek = ( src, dst, opts ) -> results = _.map src, ( t ) -> return { } if opts.assert and @hasError() tgt = _peekOne.call @, t, objPath - if tgt.fluenterror + if tgt.error tgt.quit = opts.assert @err tgt.fluenterror, tgt + tgt , @ if @hasError() and !opts.assert @@ -49,7 +50,7 @@ _peek = ( src, dst, opts ) -> ###* Peek at a single resume, resume section, or resume field. ### _peekOne = ( t, objPath ) -> - @.stat HMEVENT.beforePeek, { file: t, target: objPath } + @stat HMEVENT.beforePeek, { file: t, target: objPath } # Load the input file JSON 1st obj = safeLoadJSON t @@ -59,18 +60,20 @@ _peekOne = ( t, objPath ) -> if !obj.ex tgt = if objPath then __.get obj.json, objPath else obj.json; - # Fire the 'afterPeek' event with collected info - @.stat HMEVENT.afterPeek, - file: t - requested: objPath - target: tgt - error: obj.ex - ## safeLoadJSON can only return a READ error or a PARSE error + pkgError = null if obj.ex errCode = if obj.ex.operation == 'parse' then HMSTATUS.parseError else HMSTATUS.readError if errCode == HMSTATUS.readError obj.ex.quiet = true - return fluenterror: errCode, inner: obj.ex + pkgError = fluenterror: errCode, inner: obj.ex - tgt + + # Fire the 'afterPeek' event with collected info + @stat HMEVENT.afterPeek, + file: t + requested: objPath + target: if obj.ex then undefined else tgt + error: pkgError + + val: tgt, errpr: pkgError