Skip to content

Commit fac01f8

Browse files
committed
Better error messages when opening files.
1 parent efa57ff commit fac01f8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

preprocess.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ local function _tokenize(s, path, allowPpTokens, allowBacktickStrings, allowJitS
640640
if pat == NUM_HEX_FRAC_EXP then _, intStr, fracStr, expStr = numStrFallback:match(NUM_HEX_FRAC_EXP)
641641
elseif pat == NUM_HEX_FRAC then _, intStr, fracStr = numStrFallback:match(NUM_HEX_FRAC) ; expStr = "0"
642642
elseif pat == NUM_HEX_EXP then _, intStr, expStr = numStrFallback:match(NUM_HEX_EXP) ; fracStr = ""
643-
else assert(false) end
643+
else internalError() end
644644

645645
n = tonumber(intStr, 16) or 0 -- intStr may be "".
646646

@@ -1777,7 +1777,7 @@ function metaFuncs.outputLuaTemplate(lua, ...)
17771777
errorf(3, "Bad argument %d: %s", 1+n, err)
17781778
end
17791779

1780-
return assert(v)
1780+
return v
17811781
end)
17821782

17831783
tableInsert(current_meta_output, lua)
@@ -3575,7 +3575,9 @@ local function _processFileOrString(params, isFile)
35753575
current_meta_releaseMode = params.release
35763576

35773577
if params.pathMeta then
3578-
local file = assert(io.open(params.pathMeta, "wb"))
3578+
local file, err = io.open(params.pathMeta, "wb")
3579+
if not file then errorf("Count not open '%s' for writing. (%s)", params.pathMeta, err) end
3580+
35793581
file:write(luaMeta)
35803582
file:close()
35813583
end
@@ -3644,8 +3646,11 @@ local function _processFileOrString(params, isFile)
36443646
if pathOut == "-" then
36453647
io.stdout:write(specialFirstLine or "")
36463648
io.stdout:write(lua)
3649+
36473650
else
3648-
local file = assert(io.open(pathOut, "wb"))
3651+
local file, err = io.open(pathOut, "wb")
3652+
if not file then errorf("Count not open '%s' for writing. (%s)", pathOut, err) end
3653+
36493654
file:write(specialFirstLine or "")
36503655
file:write(lua)
36513656
file:close()

0 commit comments

Comments
 (0)