From 6fdb9eea4627fe23e24d487d0b855493178b8798 Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Mon, 24 Sep 2018 17:55:03 +0200 Subject: Fix server crash on PDF creation `markdown-pdf` seems to fail to provide the PDFs on tmpfs. This leads crashing codimd which expects the file to be there. This patch should add some proper error handling when expectation and reality don't fit together. Signed-off-by: Sheogorath --- lib/response.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/response.js b/lib/response.js index 37211998..295f91d6 100644 --- a/lib/response.js +++ b/lib/response.js @@ -341,6 +341,10 @@ function actionPDF (req, res, note) { var path = config.tmpPath + '/' + Date.now() + '.pdf' content = content.replace(/\]\(\//g, '](' + url + '/') markdownpdf().from.string(content).to(path, function () { + if (!fs.existsSync(path)) { + logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + path) + return response.errorInternalError(res) + } var stream = fs.createReadStream(path) var filename = title // Be careful of special characters -- cgit v1.2.3