luci-base: dispatcher.uc: improve error reporting for actionless nodes
authorJo-Philipp Wich <jo@mein.io>
Mon, 21 Aug 2023 07:28:18 +0000 (09:28 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 21 Aug 2023 07:48:29 +0000 (09:48 +0200)
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 <jo@mein.io>
modules/luci-base/ucode/dispatcher.uc

index f42155d5396d2fc936ae5d3e05490e18bbfa8336..8717385be2170e8eeb41f5f23fce2f1864a9c2d4 100644 (file)
@@ -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: