Skip to content

Commit 6fdb9ee

Browse files
committed
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 <[email protected]>
1 parent 32afa14 commit 6fdb9ee

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/response.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ function actionPDF (req, res, note) {
341341
var path = config.tmpPath + '/' + Date.now() + '.pdf'
342342
content = content.replace(/\]\(\//g, '](' + url + '/')
343343
markdownpdf().from.string(content).to(path, function () {
344+
if (!fs.existsSync(path)) {
345+
logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + path)
346+
return response.errorInternalError(res)
347+
}
344348
var stream = fs.createReadStream(path)
345349
var filename = title
346350
// Be careful of special characters

0 commit comments

Comments
 (0)