1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 09:59:29 +00:00

Improve error handling

This commit is contained in:
Étienne Fildadut 2021-05-17 13:59:37 +02:00
parent d68c6fab0d
commit 81f5f8fbbb
3 changed files with 296 additions and 257 deletions

14
bin/can
View file

@ -1,6 +1,6 @@
#!/usr/bin/env lua
local candran = require("candran")
local candran = require("candran").setup()
local cmdline = require("candran.cmdline")
local args = cmdline(arg)
@ -27,7 +27,11 @@ if arg[#arg] == "-" then
io.stderr:write("can: "..err.."\n")
os.exit(1)
end
f()
local r, e = xpcall(f, candran.messageHandler)
if not r then
io.stderr:write(e.."\n")
os.exit(1)
end
-- file
elseif #args >= 1 then
local f, err = candran.loadfile(args[1], nil, args)
@ -35,7 +39,11 @@ elseif #args >= 1 then
io.stderr:write("can: "..err.."\n")
os.exit(1)
else
f()
local r, e = xpcall(f, candran.messageHandler)
if not r then
io.stderr:write(e.."\n")
os.exit(1)
end
end
-- REPL
else