libs/web: more verbose faults
This commit is contained in:
parent
d970d7bd27
commit
2e618aaf29
2 changed files with 26 additions and 8 deletions
|
@ -385,11 +385,16 @@ function dispatch(request)
|
||||||
setfenv(target, env)
|
setfenv(target, env)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local ok, err
|
||||||
if type(c.target) == "table" then
|
if type(c.target) == "table" then
|
||||||
target(c.target, unpack(args))
|
ok, err = util.copcall(target, c.target, unpack(args))
|
||||||
else
|
else
|
||||||
target(unpack(args))
|
ok, err = util.copcall(target, unpack(args))
|
||||||
end
|
end
|
||||||
|
assert(ok,
|
||||||
|
"Failed to execute " .. (type(c.target) == "function" and "function" or c.target.type or "unknown") ..
|
||||||
|
" dispatcher target for entry '/" .. table.concat(request, "/") .. "'.\n" ..
|
||||||
|
"The called action terminated with an exception:\n" .. tostring(err or "(unknown)"))
|
||||||
else
|
else
|
||||||
local root = node()
|
local root = node()
|
||||||
if not root or not root.target then
|
if not root or not root.target then
|
||||||
|
@ -397,7 +402,7 @@ function dispatch(request)
|
||||||
"Install luci-admin-full and retry. " ..
|
"Install luci-admin-full and retry. " ..
|
||||||
"If the module is already installed, try removing the /tmp/luci-indexcache file.")
|
"If the module is already installed, try removing the /tmp/luci-indexcache file.")
|
||||||
else
|
else
|
||||||
error404("No page is registered at '" .. table.concat(request, "/") .. "/'.\n" ..
|
error404("No page is registered at '/" .. table.concat(request, "/") .. "'.\n" ..
|
||||||
"If this url belongs to an extension, make sure it is properly installed.\n" ..
|
"If this url belongs to an extension, make sure it is properly installed.\n" ..
|
||||||
"If the extension was recently installed, try removing the /tmp/luci-indexcache file.")
|
"If the extension was recently installed, try removing the /tmp/luci-indexcache file.")
|
||||||
end
|
end
|
||||||
|
@ -477,11 +482,20 @@ function createindex_plain(path, suffixes)
|
||||||
end
|
end
|
||||||
|
|
||||||
local mod = require(modname)
|
local mod = require(modname)
|
||||||
local idx = mod.index
|
assert(mod ~= true,
|
||||||
|
"Invalid controller file found\n" ..
|
||||||
|
"The file '" .. c .. "' contains an invalid module line.\n" ..
|
||||||
|
"Please verify whether the module name is set to '" .. modname ..
|
||||||
|
"' - It must correspond to the file path!")
|
||||||
|
|
||||||
if type(idx) == "function" then
|
local idx = mod.index
|
||||||
index[modname] = idx
|
assert(type(idx) == "function",
|
||||||
end
|
"Invalid controller file found\n" ..
|
||||||
|
"The file '" .. c .. "' contains no index() function.\n" ..
|
||||||
|
"Please make sure that the controller contains a valid " ..
|
||||||
|
"index function and verify the spelling!")
|
||||||
|
|
||||||
|
index[modname] = idx
|
||||||
end
|
end
|
||||||
|
|
||||||
if indexcache then
|
if indexcache then
|
||||||
|
|
|
@ -78,7 +78,10 @@ function Template.__init__(self, name)
|
||||||
|
|
||||||
-- If we have no valid template throw error, otherwise cache the template
|
-- If we have no valid template throw error, otherwise cache the template
|
||||||
if not self.template then
|
if not self.template then
|
||||||
error(err)
|
error("Failed to load template '" .. name .. "'.\n" ..
|
||||||
|
"Error while parsing template '" .. sourcefile .. "'.\n" ..
|
||||||
|
"A syntax error occured near '" ..
|
||||||
|
(err or "(nil)"):gsub("\t", "\\t"):gsub("\n", "\\n") .. "'.")
|
||||||
else
|
else
|
||||||
self.cache[name] = self.template
|
self.cache[name] = self.template
|
||||||
end
|
end
|
||||||
|
@ -99,6 +102,7 @@ function Template.render(self, scope)
|
||||||
-- Now finally render the thing
|
-- Now finally render the thing
|
||||||
local stat, err = util.copcall(self.template)
|
local stat, err = util.copcall(self.template)
|
||||||
if not stat then
|
if not stat then
|
||||||
error("Error in template %s: %s" % {self.name, err})
|
error("Failed to execute template '" .. self.name .. "'.\n" ..
|
||||||
|
"A runtime error occured: " .. tostring(err or "(nil)"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue