Better handle failure to open output file

This commit is contained in:
Marcel Krüger 2020-07-12 19:30:16 +02:00
parent d27e19a251
commit 5df4d5dd84
1 changed files with 5 additions and 1 deletions

View File

@ -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