Skip to content

Commit

Permalink
luci-base: dispatcher.uc: improve error reporting for actionless nodes
Browse files Browse the repository at this point in the history
In case a - potentially auto-created, intermediate - node is requested, reply
with a clean HTTP 404 error instead of an internal assertion about an unknown
action type.

Signed-off-by: Jo-Philipp Wich <[email protected]>
  • Loading branch information
jow- committed Aug 21, 2023
1 parent ec8cf9e commit 86f04d8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions modules/luci-base/ucode/dispatcher.uc
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ function render_action(fn) {
}

function run_action(request_path, lang, tree, resolved, action) {
switch (action?.type) {
switch ((type(action) == 'object') ? action.type : 'none') {
case 'template':
if (runtime.is_ucode_template(action.path))
runtime.render(action.path, {});
Expand Down Expand Up @@ -840,14 +840,19 @@ function run_action(request_path, lang, tree, resolved, action) {
break;

case 'firstchild':
if (!length(tree.children))
if (!length(tree.children)) {
error404("No root node was registered, this usually happens if no module was installed.\n" +
"Install luci-mod-admin-full and retry. " +
"If the module is already installed, try removing the /tmp/luci-indexcache file.");
else
error404(`No page is registered at '/${entityencode(join("/", resolved.ctx.request_path))}'.\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.");
break;
}

/* fall through */

case 'none':
error404(`No page is registered at '/${entityencode(join("/", resolved.ctx.request_path))}'.\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.");
break;

default:
Expand Down

0 comments on commit 86f04d8

Please sign in to comment.