From df61b5f81e39f8f63cc93fa7835a40271758faaa Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 5 Aug 2024 17:29:51 -0300 Subject: [PATCH] tl types: do not crash if given input file doesn't exist --- spec/cli/types_spec.lua | 7 +++++++ tl | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/cli/types_spec.lua b/spec/cli/types_spec.lua index c94b51d7..4c5393de 100644 --- a/spec/cli/types_spec.lua +++ b/spec/cli/types_spec.lua @@ -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") diff --git a/tl b/tl index 3e4a69ea..973c0039 100755 --- a/tl +++ b/tl @@ -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