From 5df4d5dd84504117205824470a67cad51f8de6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Sun, 12 Jul 2020 19:30:16 +0200 Subject: [PATCH] Better handle failure to open output file --- luametalatex-pdf.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/luametalatex-pdf.lua b/luametalatex-pdf.lua index bb01c5d..d157741 100644 --- a/luametalatex-pdf.lua +++ b/luametalatex-pdf.lua @@ -165,7 +165,11 @@ local pdfmeta = { } pdfmeta.__index = pdfmeta local function open(filename) - local file = io.open(filename, 'wb') + local file, msg = io.open(filename, 'wb') + if not file then + tex.error('Unable to open output file', string.format("Opening the output file %q failed. According to your system, the reason is: %q. If you continue, all output will be discarded.", filename, msg)) + file = assert(io.tmpfile()) + end file:write"%PDF-X.X\n%\xC1\xAC\xC1\xB4\n" return setmetatable({file = file, version = '1.7', [0] = 0, pages = {}, objstream = {}}, pdfmeta) end