1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 08:20:11 +00:00

Improve error handling.

This commit is contained in:
devlinjd 2015-10-07 09:29:41 -04:00
parent 279bfaae5f
commit 7ab2df6696
2 changed files with 30 additions and 17 deletions

View File

@ -9,9 +9,10 @@ module.exports = function () {
var path = require( 'path' )
, extend = require( './utils/extend' )
, unused = require('./utils/string')
, FLUENT = require('fluentlib')
, fs = require('fs')
, _ = require('underscore')
, rez, _log;
, FLUENT = require('fluentlib')
, rez, _log, _err;
/**
Given a source JSON resume, a destination resume path, and a theme file,
@ -21,19 +22,21 @@ module.exports = function () {
@param theme Friendly name of the resume theme. Defaults to "informatic".
@param logger Optional logging override.
*/
function gen( src, dst, theme, logger ) {
function gen( src, dst, theme, logger, errHandler ) {
_log = logger || console.log;
_opts.theme = theme;
var msg = '';
_err = errHandler || error;
_opts.theme = (theme && theme.toLowerCase().trim()) || 'informatic';
// Load input resumes...
if(!src || !src.length) { throw { fluenterror: 3 }; }
var sheets = src.map( function( res ) {
_log( 'Reading JSON resume: ' + res );
return (new FLUENT.Sheet()).open( res );
});
// Merge input resumes...
var msg = '';
rez = _.reduceRight( sheets, function( a, b, idx ) {
msg += ((idx == sheets.length - 2) ? 'Merging ' + a.meta.fileName : '')
+ ' onto ' + b.meta.fileName;
@ -77,18 +80,15 @@ module.exports = function () {
return fObj.gen.generate( rez, fOut, _opts.theme );
}
catch( ex ) {
err( ex );
_err( ex );
}
}
/**
Handle an exception.
*/
function err( ex ) {
var msg = ex.toString();
var idx = msg.indexOf('Error: ');
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
_log( 'ERROR: ' + trimmed.toString() );
function error( ex ) {
throw ex;
}
/**

View File

@ -6,19 +6,32 @@ Command-line interface (CLI) for FluentCMD via Node.js.
*/
var ARGS = require( 'minimist' )
, FCMD = require( './fluentcmd');
, FCMD = require( './fluentcmd')
, PKG = require('../package.json');
try {
console.log( '*** FluentCMD v0.1.0 ***' );
if( process.argv.length <= 2 ) { throw 'Please specify a JSON resume file.'; }
console.log( '*** FluentCMD v' + PKG.version + ' ***' );
if( process.argv.length <= 2 ) { throw { fluenterror: 3 }; }
var args = ARGS( process.argv.slice(2) );
var src = args._.filter( function( a ) { return a.endsWith('.json'); });
var dst = args._.filter( function( a ) { return !a.endsWith('.json'); });
var src = args._.filter( function( a ) { return a.match(/\.json$/); });
var dst = args._.filter( function( a ) { return !a.match(/\.json$/); });
FCMD.generate( src, dst, args.t || 'informatic' );
process.platform !== 'win32' && console.log('\n');
}
catch( ex ) {
var msg = ex.toString();
var msg = '';
if( ex.fluenterror ){
switch( ex.fluenterror ) {
case 1: msg = "The specified theme couldn't be found: " + ex.data; break;
case 2: msg = "Couldn't copy CSS file to destination folder"; break;
case 3: msg = "Please specify a valid JSON resume file."; break;
};
}
else {
msg = ex.toString();
}
var idx = msg.indexOf('Error: ');
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
console.log( 'ERROR: ' + trimmed.toString() );