1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-07-09 11:41:07 +01:00

Improve error handling.

Better support for spawn errors encountered during generation (for ex,
PDFs through wkhtml) + general refactoring.
This commit is contained in:
hacksalot
2015-12-29 06:35:55 -05:00
parent 13430bcad5
commit 02ef2b2241
6 changed files with 169 additions and 112 deletions

View File

@ -2,11 +2,14 @@
/**
Command-line interface (CLI) for HackMyResume.
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk.
@license MIT. Copyright (c) 2015 hacksalot (https://github.com/hacksalot)
@module index.js
*/
var ARGS = require( 'minimist' )
var SPAWNW = require('./core/spawn-watch')
, ARGS = require( 'minimist' )
, FCMD = require( './hackmycmd')
, PKG = require('../package.json')
, COLORS = require('colors')
@ -19,11 +22,12 @@ var ARGS = require( 'minimist' )
try {
main();
}
catch( ex ) {
handleError( ex );
require('./core/error-handler').err( ex, true );
}
@ -91,76 +95,3 @@ function getOpts( args ) {
silent: args.s || args.silent
};
}
// TODO: refactor
function handleError( ex ) {
var msg = '', exitCode;
if( ex.fluenterror ){
switch( ex.fluenterror ) { // TODO: Remove magic numbers
case HACKMYSTATUS.themeNotFound:
msg = "The specified theme couldn't be found: " + ex.data;
break;
case HACKMYSTATUS.copyCSS:
msg = "Couldn't copy CSS file to destination folder";
break;
case HACKMYSTATUS.resumeNotFound:
msg = 'Please '.guide + 'specify a valid input resume'.guide.bold +
' in FRESH or JSON Resume format.'.guide;
break;
case HACKMYSTATUS.missingCommand:
msg = title + "\nPlease ".guide + "specify a command".guide.bold + " (".guide +
Object.keys( FCMD.verbs ).map( function(v, idx, ar) {
return (idx === ar.length - 1 ? 'or '.guide : '') +
v.toUpperCase().guide;
}).join(', '.guide) + ").\n\n".guide +
FS.readFileSync( PATH.join(__dirname, 'use.txt'), 'utf8' ).info.bold;
break;
case HACKMYSTATUS.invalidCommand:
msg = 'Please '.guide + 'specify the output resume file'.guide.bold +
' that should be created.'.guide;
break;
case HACKMYSTATUS.resumeNotFoundAlt:
msg = 'Please '.guide + 'specify a valid input resume'.guide.bold +
' in either FRESH or JSON Resume format.'.guide;
break;
case HACKMYSTATUS.inputOutputParity:
msg = 'Please '.guide + 'specify an output file name'.guide.bold +
' for every input file you wish to convert.'.guide;
break;
case HACKMYSTATUS.createNameMissing:
msg = 'Please '.guide + 'specify the filename of the resume'.guide.bold +
' to create.'.guide;
break;
}
exitCode = ex.fluenterror;
}
else {
msg = ex.toString();
exitCode = 4;
}
var idx = msg.indexOf('Error: ');
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
if( !ex.fluenterror || ex.fluenterror < 3 ) { // TODO: magic #s
console.log( ('ERROR: ' + trimmed.toString()).red.bold );
console.log( ex.stack.gray);
}
else
console.log( trimmed.toString() );
process.exit( exitCode );
}