Skip to content

Commit

Permalink
tl types: do not crash if given input file doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Aug 5, 2024
1 parent 354e66c commit df61b5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions spec/cli/types_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ local util = require("spec.util")

describe("tl types works like check", function()
describe("on .tl files", function()
it("reports missing files", function()
local pd = io.popen(util.tl_cmd("types", "nonexistent_file") .. "2>&1 1>" .. util.os_null, "r")
local output = pd:read("*a")
util.assert_popen_close(1, pd:close())
assert.match("could not open nonexistent_file", output, 1, true)
end)

it("works on empty files", function()
local name = util.write_tmp_file(finally, [[]])
local pd = io.popen(util.tl_cmd("types", name) .. " 2>" .. util.os_null, "r")
Expand Down
12 changes: 10 additions & 2 deletions tl
Original file line number Diff line number Diff line change
Expand Up @@ -897,15 +897,23 @@ do
env.report_types = true

for i, input_file in ipairs(args["file"]) do
local pok, err = pcall(process_module, input_file, env)
local pok, perr, err = pcall(process_module, input_file, env)
if not pok then
die("Internal Compiler Error: " .. err)
die("Internal Compiler Error: " .. perr)
end
if err then
printerr(err)
end

check_collect(i)
end

local ok, _, _, w = report_all_errors(tlconfig, env)

if not env.reporter then
os.exit(1)
end

local tr = env.reporter:get_report()
if tr then
if w or not ok then
Expand Down

0 comments on commit df61b5f

Please sign in to comment.