hostapd: add wpa_supplicant ubus function guard exception handler
authorFelix Fietkau <[email protected]>
Sat, 6 Sep 2025 14:47:42 +0000 (16:47 +0200)
committerFelix Fietkau <[email protected]>
Wed, 24 Sep 2025 11:45:40 +0000 (13:45 +0200)
Improves logging when something goes wrong

Signed-off-by: Felix Fietkau <[email protected]>
package/network/services/hostapd/files/wpa_supplicant.uc

index f288121e9d4b034d051df2334056f7df52795ec9..dd371154e1ed9a3ef820c68f08b6e45cfb5241c4 100644 (file)
@@ -4,6 +4,15 @@ import { wdev_create, wdev_set_mesh_params, wdev_remove, is_equal, wdev_set_up,
 
 let ubus = libubus.connect();
 
+function ex_handler(e)
+{
+       e = split(`${e}\n${e.stacktrace[0].context}`, '\n');
+       for (let line in e)
+               wpas.printf(line);
+       return libubus.STATUS_UNKNOWN_ERROR;
+}
+libubus.guard(ex_handler);
+
 wpas.data.config = {};
 wpas.data.iface_phy = {};
 wpas.data.macaddr_list = {};
@@ -143,17 +152,13 @@ let main_obj = {
                        if (!phy)
                                return libubus.STATUS_NOT_FOUND;
 
-                       try {
-                               if (req.args.stop) {
-                                       for (let ifname in phy.data)
-                                               iface_stop(phy.data[ifname]);
-                               } else {
-                                       start_pending(name);
-                               }
-                       } catch (e) {
-                               wpas.printf(`Error chaging state: ${e}\n${e.stacktrace[0].context}`);
-                               return libubus.STATUS_INVALID_ARGUMENT;
+                       if (req.args.stop) {
+                               for (let ifname in phy.data)
+                                       iface_stop(phy.data[ifname]);
+                       } else {
+                               start_pending(name);
                        }
+
                        return 0;
                }
        },
@@ -224,16 +229,11 @@ let main_obj = {
                                return libubus.STATUS_INVALID_ARGUMENT;
 
                        wpas.printf(`Set new config for phy ${phy}`);
-                       try {
-                               if (req.args.config)
-                                       set_config(phy, req.args.phy, req.args.radio, req.args.num_global_macaddr, req.args.macaddr_base, req.args.config);
-
-                               if (!req.args.defer)
-                                       start_pending(phy);
-                       } catch (e) {
-                               wpas.printf(`Error loading config: ${e}\n${e.stacktrace[0].context}`);
-                               return libubus.STATUS_INVALID_ARGUMENT;
-                       }
+                       if (req.args.config)
+                               set_config(phy, req.args.phy, req.args.radio, req.args.num_global_macaddr, req.args.macaddr_base, req.args.config);
+
+                       if (!req.args.defer)
+                               start_pending(phy);
 
                        return {
                                pid: wpas.getpid()