Skip to content

Commit 0050572

Browse files
committed
Handle spawn errors gracefully.
1 parent 3bf4c68 commit 0050572

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/pdf.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ PDF.prototype.exec = function PdfExec (callback) {
105105
return child.kill()
106106
})
107107

108+
child.on('error', function (error) {
109+
clearTimeout(timeout)
110+
return callback(error)
111+
})
112+
108113
child.on('exit', function (code) {
109114
clearTimeout(timeout)
110115
if (code || stderr.length) {

test/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ test('allows custom html and css', function (t) {
114114
})
115115
})
116116

117+
test('allows invalid phantomPath', function (t) {
118+
t.plan(3)
119+
120+
var filename = path.join(__dirname, 'invalid-phantomPath.pdf')
121+
122+
var options = {
123+
phantomPath: '/bad/path/to/phantom'
124+
}
125+
126+
pdf
127+
.create(html, options)
128+
.toFile(filename, function (error, pdf) {
129+
t.assert(error instanceof Error, 'Returns an error')
130+
t.equal(error.code, 'ENOENT', 'Error code is ENOENT')
131+
t.error(pdf, 'PDF does not exist')
132+
})
133+
})
134+
117135
test('allows custom page and footer options', function (t) {
118136
t.plan(3)
119137

0 commit comments

Comments
 (0)