luci-base: additionally return error code strings in luci.util.ubus()
authorJo-Philipp Wich <jo@mein.io>
Tue, 24 Apr 2018 17:22:55 +0000 (19:22 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 24 Apr 2018 17:22:55 +0000 (19:22 +0200)
Add a 3rd return value to luci.util.ubus() containing the string value
of the error return value.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/luasrc/util.lua

index f47d3e5..ce42af2 100644 (file)
@@ -631,6 +631,20 @@ function execl(command)
        return data
 end
 
        return data
 end
 
+
+local ubus_codes = {
+       "INVALID_COMMAND",
+       "INVALID_ARGUMENT",
+       "METHOD_NOT_FOUND",
+       "NOT_FOUND",
+       "NO_DATA",
+       "PERMISSION_DENIED",
+       "TIMEOUT",
+       "NOT_SUPPORTED",
+       "UNKNOWN_ERROR",
+       "CONNECTION_FAILED"
+}
+
 function ubus(object, method, data)
        if not _ubus_connection then
                _ubus_connection = _ubus.connect()
 function ubus(object, method, data)
        if not _ubus_connection then
                _ubus_connection = _ubus.connect()
@@ -641,7 +655,8 @@ function ubus(object, method, data)
                if type(data) ~= "table" then
                        data = { }
                end
                if type(data) ~= "table" then
                        data = { }
                end
-               return _ubus_connection:call(object, method, data)
+               local rv, err = _ubus_connection:call(object, method, data)
+               return rv, err, ubus_codes[err]
        elseif object then
                return _ubus_connection:signatures(object)
        else
        elseif object then
                return _ubus_connection:signatures(object)
        else