1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-24 17:30:10 +00:00

Improve behavior of PEEK command.

This commit is contained in:
hacksalot 2016-01-18 18:35:38 -05:00
parent e72564162b
commit d220cedfeb
5 changed files with 33 additions and 20 deletions

View File

@ -65,7 +65,7 @@ Error-handling routines for HackMyResume.
} }
// Quit if necessary // Quit if necessary
if( objError.quit ) { if( ex.quit || 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; } if( this.assert ) { ex.pass = true; throw ex; }
@ -85,6 +85,7 @@ Error-handling routines for HackMyResume.
}, },
formatError: function( msg ) { formatError: function( msg ) {
msg = msg || '';
return chalk.red.bold( return chalk.red.bold(
msg.toUpperCase().startsWith('ERROR:') ? msg : 'Error: ' + msg ); msg.toUpperCase().startsWith('ERROR:') ? msg : 'Error: ' + msg );
}, },
@ -102,7 +103,7 @@ Error-handling routines for HackMyResume.
function assembleError( ex ) { function assembleError( ex ) {
var msg = '', withStack = false, isError = false, quit = true, warn = true; var msg = '', withStack = false, isError = false, quit = false, warn = true;
if( this.debug ) withStack = true; if( this.debug ) withStack = true;
switch( ex.fluenterror ) { switch( ex.fluenterror ) {
@ -190,7 +191,7 @@ Error-handling routines for HackMyResume.
break; break;
case HMSTATUS.readError: case HMSTATUS.readError:
console.error( printf( M2C(this.msgs.readError.msg, 'red'), ex.file ) ); if( !ex.quiet ) console.error( printf( M2C(this.msgs.readError.msg, 'red'), ex.file ) );
msg = ex.inner.toString(); msg = ex.inner.toString();
warn = false; warn = false;
break; break;
@ -202,10 +203,15 @@ Error-handling routines for HackMyResume.
case HMSTATUS.parseError: case HMSTATUS.parseError:
if( SyntaxErrorEx.is( ex.inner )) { if( SyntaxErrorEx.is( ex.inner )) {
console.error( printf( M2C(this.msgs.readError.msg, 'red'), ex.file ) );
var se = new SyntaxErrorEx( ex, ex.raw ); var se = new SyntaxErrorEx( ex, ex.raw );
msg = printf( M2C( this.msgs.parseError.msg, 'red' ), msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
se.line, se.col); se.line, se.col);
} }
else if( ex.inner && ex.inner.line !== undefined && ex.inner.col !== undefined ) {
msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
ex.inner.line, ex.inner.col);
}
else { else {
msg = ex; msg = ex;
} }

View File

@ -198,9 +198,9 @@ Output routines for HackMyResume.
case HME.beforePeek: case HME.beforePeek:
if( evt.target ) if( evt.target )
L(M2C(this.msgs.beforePeek.msg[0], 'cyan'), evt.target, evt.file); L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file);
else else
L(M2C(this.msgs.beforePeek.msg[1], 'cyan'), evt.file); L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
break; break;
case HME.afterPeek: case HME.afterPeek:

View File

@ -125,6 +125,7 @@ Definition of the ResumeFactory class.
fluenterror: rawData ? HACKMYSTATUS.parseError : HACKMYSTATUS.readError, fluenterror: rawData ? HACKMYSTATUS.parseError : HACKMYSTATUS.readError,
inner: e, raw: rawData, file: fileName, shouldExit: false inner: e, raw: rawData, file: fileName, shouldExit: false
}; };
opts.quit && (ex.quit = true);
eve && eve.err( ex.fluenterror, ex ); eve && eve.err( ex.fluenterror, ex );
if( opts.throw ) throw ex; if( opts.throw ) throw ex;
return ex; return ex;

View File

@ -11,7 +11,6 @@ Definition of the SafeJsonLoader class.
var FS = require('fs') var FS = require('fs')
, HMSTATUS = require('../core/status-codes')
, SyntaxErrorEx = require('./syntax-error-ex'); , SyntaxErrorEx = require('./syntax-error-ex');
@ -29,14 +28,12 @@ Definition of the SafeJsonLoader class.
// If we get here, either FS.readFileSync or JSON.parse failed. // If we get here, either FS.readFileSync or JSON.parse failed.
// We'll return HMSTATUS.readError or HMSTATUS.parseError. // We'll return HMSTATUS.readError or HMSTATUS.parseError.
ret.ex = ( ret.raw && ret.raw.trim() ) ? var retRaw = ret.raw && ret.raw.trim();
{ // JSON.parse failed, likely because of a SyntaxError
fluenterror: HMSTATUS.parseError, ret.ex = {
inner: SyntaxErrorEx.is( ex ) ? new SyntaxErrorEx( ex ) : ex operation: retRaw ? 'parse' : 'read',
} : inner: SyntaxErrorEx.is( ex ) ? (new SyntaxErrorEx( ex, retRaw )) : ex,
{ // FS.readFileSync failed, likely because of ENOENT or EACCES file: file
fluenterror: HMSTATUS.readError,
inner: ex
}; };
} }

View File

@ -45,15 +45,24 @@ Implementation of the 'peek' verb for HackMyResume.
var objPath = (dst && dst[0]) || ''; var objPath = (dst && dst[0]) || '';
_.each( src, function( t ) { _.each( src, function( t ) {
this.stat( HMEVENT.beforePeek, { file: t, target: objPath } );
var obj = safeLoadJSON( t ); var obj = safeLoadJSON( t );
if( obj.ex ) { this.stat( HMEVENT.beforePeek, { file: t, target: objPath, isError: obj.ex } );
this.err( obj.ex.fluenterror, obj.ex );
}
var targ = objPath ? __.get( obj.json, objPath ) : obj.json;
if( obj.ex ) {
if( obj.ex.operation === 'parse' )
this.err( HMSTATUS.parseError, obj.ex );
else {
obj.ex.quiet = true;
this.err( HMSTATUS.readError, obj.ex );
}
return;
}
var targ = objPath ? __.get( obj.json, objPath ) : obj.json;
this.stat( HMEVENT.afterPeek, { file: t, requested: objPath, target: targ } ); this.stat( HMEVENT.afterPeek, { file: t, requested: objPath, target: targ } );
}, this); }, this);
} }