the lua shell now catches errors dealt by libraries, and puts them on a log file
there's also lazyvim formatting everything, as usual
This commit is contained in:
+33
-1
@@ -1,14 +1,44 @@
|
|||||||
-- terminal.readHistory["lua"] = {""}
|
-- terminal.readHistory["lua"] = {""}
|
||||||
local fs = require("filesystem")
|
local fs = require("filesystem")
|
||||||
local computer = require("computer")
|
local computer = require("computer")
|
||||||
|
local log = require("log")
|
||||||
|
|
||||||
local bootTime = computer.uptime()
|
local bootTime = computer.uptime()
|
||||||
local libList = fs.list("/lib/")
|
local libList = fs.list("/lib/")
|
||||||
|
local failed = false
|
||||||
for _, lib in pairs(libList) do
|
for _, lib in pairs(libList) do
|
||||||
|
local status, err = xpcall(function()
|
||||||
if lib:match("(.+)%.lua") then
|
if lib:match("(.+)%.lua") then
|
||||||
local name = lib:match("(.+)%.lua")
|
local name = lib:match("(.+)%.lua")
|
||||||
_G[name] = require(name)
|
_G[name] = require(name)
|
||||||
end
|
end
|
||||||
|
end, debug.traceback)
|
||||||
|
if not status then
|
||||||
|
print(
|
||||||
|
string.format(
|
||||||
|
"\x1b[91mLibrary %s has failed loading:\n │ %s",
|
||||||
|
lib:match("(.+)%.lua"),
|
||||||
|
tostring(err or "unknown error"):match("^(.-)\n")
|
||||||
|
)
|
||||||
|
) -- TODO: only show first line of error
|
||||||
|
log.lua.error(
|
||||||
|
string.format(
|
||||||
|
'The library located at "%s" has failed loading:\n%s',
|
||||||
|
lib,
|
||||||
|
type(err) ~= "nil" and tostring(err) or "unknown error"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
failed = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if failed then
|
||||||
|
print(
|
||||||
|
string.format(
|
||||||
|
'\x1b[93mOne or more libraries failed to load. For more information, check the log entries located at "%s".',
|
||||||
|
tostring(log.lua.logpath or "[unknown]")
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
print(string.format("\27[37mLoaded %d libraries in %.2f seconds\27[0m", #libList, computer.uptime() - bootTime))
|
print(string.format("\27[37mLoaded %d libraries in %.2f seconds\27[0m", #libList, computer.uptime() - bootTime))
|
||||||
@@ -23,7 +53,9 @@ while true do
|
|||||||
local function runCommand()
|
local function runCommand()
|
||||||
local func = load("return " .. command, "=stdin") or load(command, "=stdin")
|
local func = load("return " .. command, "=stdin") or load(command, "=stdin")
|
||||||
local res = { assert(func)() }
|
local res = { assert(func)() }
|
||||||
if res and (type(res[1])~="nil" or type(res[2])~="nil") then print(table.unpack(res)) end
|
if res and (type(res[1]) ~= "nil" or type(res[2]) ~= "nil") then
|
||||||
|
print(table.unpack(res))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local result, reason = xpcall(runCommand, function(errMsg)
|
local result, reason = xpcall(runCommand, function(errMsg)
|
||||||
return errMsg .. "\n\n" .. debug.traceback()
|
return errMsg .. "\n\n" .. debug.traceback()
|
||||||
|
|||||||
Reference in New Issue
Block a user