@@ -123,14 +123,17 @@ PDF.prototype.exec = function PdfExec (callback) {
123
123
// Ignore if code has a value of 0 since that means PhantomJS has executed and exited successfully.
124
124
// Also, as per your script and standards, having a code value of 1 means one can always assume that
125
125
// 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 ) ) {
127
127
var error = null
128
128
129
129
if ( err ) {
130
130
// Rudimentary checking if err is an instance of the Error class
131
131
error = err instanceof Error ? err : new Error ( err )
132
+ } else if ( code === 0 && ! data ) {
133
+ // This is to catch the edge case of having an exit code value of 0 but not having data (exit can be called before io pipes are closed)
134
+ error = new Error ( 'html-pdf: Process exited successfully, but no data received' )
132
135
} 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
134
137
error = new Error ( 'html-pdf: Unknown Error' )
135
138
}
136
139
@@ -150,7 +153,7 @@ PDF.prototype.exec = function PdfExec (callback) {
150
153
151
154
// An exit event is most likely an error because we didn't get any data at this point
152
155
child . on ( 'close' , respond )
153
- child . on ( 'exit' , respond )
156
+ // child.on('exit', respond)
154
157
155
158
var config = JSON . stringify ( { html : this . html , options : this . options } )
156
159
child . stdin . write ( config + '\n' , 'utf8' )
0 commit comments