From 86f04d85fc774db9cb7e60a34a50f936d8d7be23 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 21 Aug 2023 09:28:18 +0200 Subject: [PATCH] luci-base: dispatcher.uc: improve error reporting for actionless nodes 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 --- modules/luci-base/ucode/dispatcher.uc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/luci-base/ucode/dispatcher.uc b/modules/luci-base/ucode/dispatcher.uc index f42155d539..8717385be2 100644 --- a/modules/luci-base/ucode/dispatcher.uc +++ b/modules/luci-base/ucode/dispatcher.uc @@ -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, {}); @@ -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: