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

Improve error handling: PDFs.

This commit is contained in:
hacksalot 2016-01-08 05:11:38 -05:00
parent 0246a5da19
commit 28c703daf7
3 changed files with 32 additions and 9 deletions

View File

@ -73,7 +73,8 @@ Error-handling routines for HackMyResume.
function get_error_msg( ex ) { function get_error_msg( ex ) {
var msg = '', withStack = false;
var msg = '', withStack = false, isError = false;
switch( ex.fluenterror ) { switch( ex.fluenterror ) {
case HACKMYSTATUS.themeNotFound: case HACKMYSTATUS.themeNotFound:
@ -137,6 +138,10 @@ Error-handling routines for HackMyResume.
}); });
break; break;
case HACKMYSTATUS.notOnPath:
msg = formatError( ex.engine + " wasn't found on your system path or is inaccessible. PDF not generated." );
break;
} }
return { return {
msg: msg, msg: msg,
@ -144,6 +149,9 @@ Error-handling routines for HackMyResume.
}; };
} }
function formatError( msg ) {
return chalk.red.bold( 'ERROR: ' + msg );
}
}()); }());

View File

@ -19,7 +19,8 @@ Status codes for HackMyResume.
pdfgeneration: 9, pdfgeneration: 9,
missingPackageJSON: 10, missingPackageJSON: 10,
invalid: 11, invalid: 11,
invalidTarget: 12 invalidTarget: 12,
notOnPath: 13
}; };
}()); }());

View File

@ -37,14 +37,16 @@ Definition of the HtmlPdfCLIGenerator class.
*/ */
onBeforeSave: function( info ) { onBeforeSave: function( info ) {
try { try {
engines[ info.opts.pdf || 'wkhtmltopdf' ] var safe_eng = info.opts.pdf || 'wkhtmltopdf';
.call( this, info.mk, info.outputFile ); engines[ safe_eng ].call( this, info.mk, info.outputFile );
return null; // halt further processing return null; // halt further processing
} }
catch(ex) { catch(ex) {
// { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', ... } // { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', ... }
// { [Error: ENOENT] } // { [Error: ENOENT] }
throw { fluenterror: this.codes.pdfGeneration, inner: ex }; throw ( ex.inner && ex.inner.code === 'ENOENT' ) ?
{ fluenterror: this.codes.notOnPath, engine: ex.cmd } :
{ fluenterror: this.codes.pdfGeneration, inner: ex.inner };
} }
} }
@ -65,10 +67,16 @@ Definition of the HtmlPdfCLIGenerator class.
var tempFile = fOut.replace(/\.pdf$/i, '.pdf.html'); var tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
FS.writeFileSync( tempFile, markup, 'utf8' ); FS.writeFileSync( tempFile, markup, 'utf8' );
var spawn = require('child_process').spawn; var spawn = require('child_process').spawnSync;
var child = spawn('wkhtmltopdf', [ var info = spawn('wkhtmltopdf', [
tempFile, fOut tempFile, fOut
]); ]);
if( info.error ) {
throw {
cmd: 'wkhtmltopdf',
inner: info.error
};
}
// child.stdout.on('data', function(chunk) { // child.stdout.on('data', function(chunk) {
// // output will be here in chunks // // output will be here in chunks
@ -95,8 +103,14 @@ Definition of the HtmlPdfCLIGenerator class.
var sourcePath = SLASH( PATH.relative( process.cwd(), tempFile) ); var sourcePath = SLASH( PATH.relative( process.cwd(), tempFile) );
var destPath = SLASH( PATH.relative( process.cwd(), fOut) ); var destPath = SLASH( PATH.relative( process.cwd(), fOut) );
var spawn = require('child_process').spawn; var spawn = require('child_process').spawnSync;
var child = spawn('phantomjs', [ scriptPath, sourcePath, destPath ]); var info = spawn('1phantomjs', [ scriptPath, sourcePath, destPath ]);
if( info.error ) {
throw {
cmd: 'phantomjs',
inner: info.error
};
}
// child.stdout.on('data', function(chunk) { // child.stdout.on('data', function(chunk) {
// // output will be here in chunks // // output will be here in chunks