summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2011-07-21 01:04:53 +0000
committerJo-Philipp Wich <jow@openwrt.org>2011-07-21 01:04:53 +0000
commit2e618aaf294832b8b7cbfaa31d82f16d350b30c6 (patch)
tree05aec6c2bf7c456d660500d0dea124bb3061e9f3 /libs
parentd970d7bd27cf9f4b6cdbec5737ed72291c0896d2 (diff)
libs/web: more verbose faults
Diffstat (limited to 'libs')
-rw-r--r--libs/web/luasrc/dispatcher.lua26
-rw-r--r--libs/web/luasrc/template.lua8
2 files changed, 26 insertions, 8 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua
index 8da10812b..e29bd52bc 100644
--- a/libs/web/luasrc/dispatcher.lua
+++ b/libs/web/luasrc/dispatcher.lua
@@ -385,11 +385,16 @@ function dispatch(request)
setfenv(target, env)
end)
+ local ok, err
if type(c.target) == "table" then
- target(c.target, unpack(args))
+ ok, err = util.copcall(target, c.target, unpack(args))
else
- target(unpack(args))
+ ok, err = util.copcall(target, unpack(args))
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
local root = node()
if not root or not root.target then
@@ -397,7 +402,7 @@ function dispatch(request)
"Install luci-admin-full and retry. " ..
"If the module is already installed, try removing the /tmp/luci-indexcache file.")
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 the extension was recently installed, try removing the /tmp/luci-indexcache file.")
end
@@ -477,11 +482,20 @@ function createindex_plain(path, suffixes)
end
local mod = require(modname)
+ 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!")
+
local idx = mod.index
+ assert(type(idx) == "function",
+ "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!")
- if type(idx) == "function" then
- index[modname] = idx
- end
+ index[modname] = idx
end
if indexcache then
diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua
index 80a3206af..962c2ea88 100644
--- a/libs/web/luasrc/template.lua
+++ b/libs/web/luasrc/template.lua
@@ -78,7 +78,10 @@ function Template.__init__(self, name)
-- If we have no valid template throw error, otherwise cache the template
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
self.cache[name] = self.template
end
@@ -99,6 +102,7 @@ function Template.render(self, scope)
-- Now finally render the thing
local stat, err = util.copcall(self.template)
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