mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-06-30 23:51:05 +01:00
Introduce PEEK command.
Peek at arbitrary resumes and resume objects paths with "hackmyresume peek <resume> [objectPath]". For ex: hackmyresume PEEK resume.json hackmyresume PEEK resume.json info hackmyresume PEEK resume.json employment[2].keywords hackmyresume PEEK r1.json r2.json r3.json info.brief
This commit is contained in:
@ -8,16 +8,41 @@ Definition of the SafeJsonLoader class.
|
||||
|
||||
(function() {
|
||||
|
||||
var FS = require('fs');
|
||||
|
||||
|
||||
var FS = require('fs')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, SyntaxErrorEx = require('./syntax-error-ex');
|
||||
|
||||
|
||||
|
||||
module.exports = function loadSafeJson( file ) {
|
||||
|
||||
var ret = { };
|
||||
try {
|
||||
return JSON.parse( FS.readFileSync( file ) );
|
||||
|
||||
ret.raw = FS.readFileSync( file, 'utf8' );
|
||||
ret.json = JSON.parse( ret.raw );
|
||||
|
||||
}
|
||||
catch(ex) {
|
||||
loadSafeJson.error = ex;
|
||||
catch( ex ) {
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
return ret;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user