Index: stand/lua/core.lua =================================================================== --- stand/lua/core.lua +++ stand/lua/core.lua @@ -68,8 +68,8 @@ -- Globals --- try_include will return the loaded module on success, or false and the error --- message on failure. +-- try_include will return the loaded module or true on success (module loaded +-- or file does not exist), or false and the error message on failure. function try_include(module) if module:sub(1, 1) ~= "/" then local lua_path = loader.lua_path @@ -88,11 +88,27 @@ module = module .. ".lua" end end - if lfs.attributes(module, "mode") ~= "file" then - return + + -- If the file doesn't exist, just pretend we succeeded... if it does + -- exist but it's not a regular file, then that's an actual error. + -- try_include doesn't guarantee that it won't trip over weird entries, + -- just that it won't trip over nonexistent entries. + local mode = lfs.attributes(module, 'mode') + if not mode then + return true + elseif mode ~= "file" then + return nil, module .. " is not a regular file." + end + + local function unwrap_result(res, mod, ...) + if res then + return mod or true, ... + else + return res, mod + end end - return dofile(module) + return unwrap_result(pcall(dofile, module)) end -- Module exports Index: stand/lua/loader.lua =================================================================== --- stand/lua/loader.lua +++ stand/lua/loader.lua @@ -49,7 +49,13 @@ if color.isEnabled() then printc(core.KEYSTR_RESET) end -try_include("local") +local res, err = try_include("local") +if not res then + -- Our error object may not be as helpful as we wanted... we'll try + -- to stringify it in case a local object is trying to error() some + -- odd non-stringable object (e.g., a table). + print("Local module failed, error: " .. tostring(err)) +end password.check() if not core.isMenuSkipped() then require("menu").run()