1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +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 ) {
var msg = '', withStack = false;
var msg = '', withStack = false, isError = false;
switch( ex.fluenterror ) {
case HACKMYSTATUS.themeNotFound:
@ -137,6 +138,10 @@ Error-handling routines for HackMyResume.
});
break;
case HACKMYSTATUS.notOnPath:
msg = formatError( ex.engine + " wasn't found on your system path or is inaccessible. PDF not generated." );
break;
}
return {
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,
missingPackageJSON: 10,
invalid: 11,
invalidTarget: 12
invalidTarget: 12,
notOnPath: 13
};
}());

View File

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