mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 01:56:21 +00:00
Improve behavior of PEEK command.
This commit is contained in:
parent
e72564162b
commit
d220cedfeb
@ -65,7 +65,7 @@ Error-handling routines for HackMyResume.
|
||||
}
|
||||
|
||||
// Quit if necessary
|
||||
if( objError.quit ) {
|
||||
if( ex.quit || objError.quit ) {
|
||||
this.debug && o(
|
||||
chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
|
||||
if( this.assert ) { ex.pass = true; throw ex; }
|
||||
@ -85,6 +85,7 @@ Error-handling routines for HackMyResume.
|
||||
},
|
||||
|
||||
formatError: function( msg ) {
|
||||
msg = msg || '';
|
||||
return chalk.red.bold(
|
||||
msg.toUpperCase().startsWith('ERROR:') ? msg : 'Error: ' + msg );
|
||||
},
|
||||
@ -102,7 +103,7 @@ Error-handling routines for HackMyResume.
|
||||
|
||||
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;
|
||||
|
||||
switch( ex.fluenterror ) {
|
||||
@ -190,7 +191,7 @@ Error-handling routines for HackMyResume.
|
||||
break;
|
||||
|
||||
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();
|
||||
warn = false;
|
||||
break;
|
||||
@ -202,10 +203,15 @@ Error-handling routines for HackMyResume.
|
||||
|
||||
case HMSTATUS.parseError:
|
||||
if( SyntaxErrorEx.is( ex.inner )) {
|
||||
console.error( printf( M2C(this.msgs.readError.msg, 'red'), ex.file ) );
|
||||
var se = new SyntaxErrorEx( ex, ex.raw );
|
||||
msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
|
||||
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 {
|
||||
msg = ex;
|
||||
}
|
||||
|
@ -198,9 +198,9 @@ Output routines for HackMyResume.
|
||||
|
||||
case HME.beforePeek:
|
||||
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
|
||||
L(M2C(this.msgs.beforePeek.msg[1], 'cyan'), evt.file);
|
||||
L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
|
||||
break;
|
||||
|
||||
case HME.afterPeek:
|
||||
|
@ -125,6 +125,7 @@ Definition of the ResumeFactory class.
|
||||
fluenterror: rawData ? HACKMYSTATUS.parseError : HACKMYSTATUS.readError,
|
||||
inner: e, raw: rawData, file: fileName, shouldExit: false
|
||||
};
|
||||
opts.quit && (ex.quit = true);
|
||||
eve && eve.err( ex.fluenterror, ex );
|
||||
if( opts.throw ) throw ex;
|
||||
return ex;
|
||||
|
@ -11,7 +11,6 @@ Definition of the SafeJsonLoader class.
|
||||
|
||||
|
||||
var FS = require('fs')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, SyntaxErrorEx = require('./syntax-error-ex');
|
||||
|
||||
|
||||
@ -29,15 +28,13 @@ Definition of the SafeJsonLoader class.
|
||||
|
||||
// If we get here, either FS.readFileSync or JSON.parse failed.
|
||||
// We'll return HMSTATUS.readError or HMSTATUS.parseError.
|
||||
ret.ex = ( ret.raw && ret.raw.trim() ) ?
|
||||
{ // JSON.parse failed, likely because of a SyntaxError
|
||||
fluenterror: HMSTATUS.parseError,
|
||||
inner: SyntaxErrorEx.is( ex ) ? new SyntaxErrorEx( ex ) : ex
|
||||
} :
|
||||
{ // FS.readFileSync failed, likely because of ENOENT or EACCES
|
||||
fluenterror: HMSTATUS.readError,
|
||||
inner: ex
|
||||
};
|
||||
var retRaw = ret.raw && ret.raw.trim();
|
||||
|
||||
ret.ex = {
|
||||
operation: retRaw ? 'parse' : 'read',
|
||||
inner: SyntaxErrorEx.is( ex ) ? (new SyntaxErrorEx( ex, retRaw )) : ex,
|
||||
file: file
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -45,15 +45,24 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
var objPath = (dst && dst[0]) || '';
|
||||
|
||||
_.each( src, function( t ) {
|
||||
this.stat( HMEVENT.beforePeek, { file: t, target: objPath } );
|
||||
|
||||
var obj = safeLoadJSON( t );
|
||||
if( obj.ex ) {
|
||||
this.err( obj.ex.fluenterror, obj.ex );
|
||||
}
|
||||
var targ = objPath ? __.get( obj.json, objPath ) : obj.json;
|
||||
this.stat( HMEVENT.beforePeek, { file: t, target: objPath, isError: obj.ex } );
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user