From 67e5021741bf21386d630a7b4a68ef567c012b6b Mon Sep 17 00:00:00 2001 From: Omri Litvak <9881966+omrilit@users.noreply.github.com> Date: Wed, 18 Aug 2021 11:04:51 +0300 Subject: [PATCH] SAAS-2669: throw error explicitly using the callback instead of failing due to "Cannot read property 'filename' of undefined" (#1) --- lib/pdf.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pdf.js b/lib/pdf.js index 46f2ce4..300abf5 100644 --- a/lib/pdf.js +++ b/lib/pdf.js @@ -45,6 +45,7 @@ function PDF (html, options) { PDF.prototype.toBuffer = function PdfToBuffer (callback) { this.exec(function execPdfToBuffer (err, res) { if (err) return callback(err) + if (!res) return callback(new Error('html-pdf: PDF generation failed due to an unknown reason')) fs.readFile(res.filename, function readCallback (err, buffer) { if (err) return callback(err) fs.unlink(res.filename, function unlinkPdfFile (err) {