From 2b669cf35c0f7aabac4cf6c16d93f7704775091f Mon Sep 17 00:00:00 2001 From: hacksalot Date: Fri, 1 Jan 2016 15:06:16 -0500 Subject: [PATCH] Tweak error handling for cmd params. --- src/core/resume-factory.js | 12 +++++++++++- src/index.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/resume-factory.js b/src/core/resume-factory.js index 08becdc..8bf0f83 100644 --- a/src/core/resume-factory.js +++ b/src/core/resume-factory.js @@ -88,17 +88,27 @@ Definition of the ResumeFactory class. // TODO: Core should not log log( chalk.gray('Reading resume: ') + chalk.cyan.bold(fileName) ); + // Read the file rawData = FS.readFileSync( fileName, 'utf8' ); + + // Parse it to JSON return { json: JSON.parse( rawData ) }; } - catch(ex) { + catch( ex ) { + + // If FS.readFileSync threw, pass the exception along. + if (!rawData) + throw ex; + + // Otherwise if JSON.parse failed: probably a SyntaxError. return { error: ex, raw: rawData }; + } } diff --git a/src/index.js b/src/index.js index b54a1a5..dad71a7 100644 --- a/src/index.js +++ b/src/index.js @@ -35,8 +35,8 @@ catch( ex ) { function main() { // Setup - if( process.argv.length <= 2 ) { throw { fluenterror: 4 }; } var a = ARGS( process.argv.slice(2) ); + if( a._.length === 0 ) { throw { fluenterror: 4 }; } opts = getOpts( a ); logMsg( title );