1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-10 15:57:07 +01:00

Catch JSON syntax errors for all commands.

...and emit line/column info.
This commit is contained in:
hacksalot
2016-01-01 17:20:42 -05:00
parent 8c8dbfed72
commit 13fc903b2b
5 changed files with 49 additions and 20 deletions

View File

@ -23,7 +23,7 @@ Implementation of the 'convert' verb for HackMyResume.
if( sources && dst && sources.length && dst.length && sources.length !== dst.length ) {
throw { fluenterror: 7 };
}
var sourceResumes = ResumeFactory.load( sources, _log, null, true );
var sourceResumes = ResumeFactory.load( sources, { log: _log, format: null, objectify: true, throw: true } );
sourceResumes.forEach(function( src, idx ) {
var sheet = src.rez;
var sourceFormat = ((sheet.basics && sheet.basics.imp) || sheet.imp).orgFormat === 'JRS' ? 'JRS' : 'FRESH';

View File

@ -59,7 +59,9 @@ Implementation of the 'generate' verb for HackMyResume.
// Load input resumes...
if( !src || !src.length ) { throw { fluenterror: 3 }; }
var sheets = ResumeFactory.load(src, _log, theme.render ? 'JRS' : 'FRESH', true);
var sheets = ResumeFactory.load(src, {
log: _log, format: theme.render ? 'JRS' : 'FRESH', objectify: true, throw: true
});
// Merge input resumes...
var msg = '';

View File

@ -30,17 +30,26 @@ Implementation of the 'validate' verb for HackMyResume.
// Load input resumes...
sources.forEach(function( src ) {
var result = ResumeFactory.loadOne( src, function(){}, null, false );
var result = ResumeFactory.loadOne( src, {
log: function(){},
format: null,
objectify: false,
throw: false
});
if( result.error ) {
_log( chalk.white('Validating ') + chalk.gray.bold(src) + chalk.white(' against ') + chalk.gray.bold('AUTO') + chalk.white(' schema:') + chalk.red.bold(' BROKEN') );
// TODO: Core should not log
_log( chalk.white('Validating ') + chalk.gray.bold(src) +
chalk.white(' against ') + chalk.gray.bold('AUTO') +
chalk.white(' schema:') + chalk.red.bold(' BROKEN') );
var ex = result.error; // alias
if ( ex instanceof SyntaxError) {
var info = new SyntaxErrorEx( ex, result.raw );
_log( chalk.red.bold('--> ') + chalk.red(src.toUpperCase() + ' contains invalid JSON on line ' +
info.line + ' column ' + info.col + '.') +
chalk.red(' Unable to validate.') );
_log( chalk.red(' INTERNAL: ' + ex) );
_log( chalk.red.bold('--> ' + src.toUpperCase() + ' contains invalid JSON on line ' +
info.line + ' column ' + info.col + '.' +
chalk.red(' Unable to validate.') ) );
_log( chalk.red.bold(' INTERNAL: ' + ex) );
}
else {
_log(chalk.red.bold('ERROR: ' + ex.toString()));