@@ -123,14 +123,17 @@ PDF.prototype.exec = function PdfExec (callback) {
123123 // Ignore if code has a value of 0 since that means PhantomJS has executed and exited successfully.
124124 // Also, as per your script and standards, having a code value of 1 means one can always assume that
125125 // an error occured.
126- if ( ( ( typeof code !== 'undefined' && code !== null ) && code !== 0 ) || err ) {
126+ if ( ( ( typeof code !== 'undefined' && code !== null ) && code !== 0 ) || err || ( code === 0 && ! data ) ) {
127127 var error = null
128128
129129 if ( err ) {
130130 // Rudimentary checking if err is an instance of the Error class
131131 error = err instanceof Error ? err : new Error ( err )
132+ } else if ( code === 0 && ! data ) {
133+ // This is to catch the edge case of having a exit code value of 0 but having no data (exit can be called before io pipes are closed)
134+ error = new Error ( 'html-pdf: Process exited successfully, but no data received' )
132135 } else {
133- // This is to catch the edge case of having a exit code value of 1 but having no error
136+ // This is to catch the edge case of having an exit code value of 1 but having no error
134137 error = new Error ( 'html-pdf: Unknown Error' )
135138 }
136139
@@ -150,7 +153,7 @@ PDF.prototype.exec = function PdfExec (callback) {
150153
151154 // An exit event is most likely an error because we didn't get any data at this point
152155 child . on ( 'close' , respond )
153- child . on ( 'exit' , respond )
156+ // child.on('exit', respond)
154157
155158 var config = JSON . stringify ( { html : this . html , options : this . options } )
156159 child . stdin . write ( config + '\n' , 'utf8' )
0 commit comments