2015-12-29 11:35:55 +00:00
|
|
|
/**
|
|
|
|
@module error-handler.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
var HACKMYSTATUS = require('./status-codes')
|
|
|
|
, PKG = require('../../package.json')
|
2015-12-30 17:59:21 +00:00
|
|
|
, FS = require('fs')
|
|
|
|
, FCMD = require('../hackmycmd')
|
|
|
|
, PATH = require('path')
|
2016-01-01 09:44:14 +00:00
|
|
|
, chalk = require('chalk')
|
|
|
|
, title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***');
|
2015-12-29 11:35:55 +00:00
|
|
|
|
|
|
|
var ErrorHandler = module.exports = {
|
|
|
|
|
|
|
|
|
|
|
|
err: function( ex, shouldExit ) {
|
|
|
|
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:
|
2016-01-01 09:44:14 +00:00
|
|
|
msg = chalk.yellow('Please ') + chalk.yellow.bold('feed me a resume') +
|
|
|
|
chalk.yellow(' in FRESH or JSON Resume format.');
|
2015-12-29 11:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HACKMYSTATUS.missingCommand:
|
2016-01-01 09:44:14 +00:00
|
|
|
msg = title + chalk.yellow("\nPlease ") + chalk.yellow.bold("give me a command") +
|
|
|
|
chalk.yellow(" (");
|
2015-12-30 18:12:51 +00:00
|
|
|
|
|
|
|
msg += Object.keys( FCMD.verbs ).map( function(v, idx, ar) {
|
2016-01-01 09:44:14 +00:00
|
|
|
return (idx === ar.length - 1 ? chalk.yellow('or ') : '') +
|
|
|
|
chalk.yellow.bold(v.toUpperCase());
|
|
|
|
}).join( chalk.yellow(', ')) + chalk.yellow(").\n\n");
|
2015-12-30 18:12:51 +00:00
|
|
|
|
2016-01-01 09:44:14 +00:00
|
|
|
msg += chalk.gray(FS.readFileSync( PATH.resolve(__dirname, '../use.txt'), 'utf8' ));
|
2015-12-29 11:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HACKMYSTATUS.invalidCommand:
|
2016-01-01 09:44:14 +00:00
|
|
|
msg = chalk.yellow('Please ') + chalk.yellow.bold('specify the output resume file') +
|
|
|
|
chalk.yellow(' that should be created.');
|
2015-12-29 11:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HACKMYSTATUS.resumeNotFoundAlt:
|
2016-01-01 09:44:14 +00:00
|
|
|
msg = chalk.yellow('Please ') + chalk.yellow.bold('feed me a resume') +
|
|
|
|
chalk.yellow(' in either FRESH or JSON Resume format.');
|
2015-12-29 11:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HACKMYSTATUS.inputOutputParity:
|
2016-01-01 09:44:14 +00:00
|
|
|
msg = chalk.yellow('Please ') + chalk.yellow.bold('specify an output file name') +
|
|
|
|
chalk.yellow(' for every input file you wish to convert.');
|
2015-12-29 11:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HACKMYSTATUS.createNameMissing:
|
2016-01-01 09:44:14 +00:00
|
|
|
msg = chalk.yellow('Please ') + chalk.yellow.bold('specify the filename of the resume') +
|
|
|
|
chalk.yellow(' to create.');
|
2015-12-29 11:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HACKMYSTATUS.wkhtmltopdf:
|
2016-01-01 09:44:14 +00:00
|
|
|
msg = chalk.red.bold('ERROR: PDF generation failed. ') + chalk.red('Make sure wkhtmltopdf is ' +
|
|
|
|
'installed and accessible from your path.');
|
2015-12-29 11:35:55 +00:00
|
|
|
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
|
2016-01-01 09:44:14 +00:00
|
|
|
console.log( chalk.red.bold('ERROR: ' + trimmed.toString()) );
|
|
|
|
console.log( chalk.gray(ex.stack) );
|
2015-12-29 11:35:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log( trimmed.toString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( shouldExit )
|
|
|
|
process.exit( exitCode );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|