SunPanel报错:attempt to index local 'obj' (a nil value)

故障现象

通过istore安装SunPanel,安装过程正常,但无法打开网页,并出现如下lua报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Runtime error
Unhandled exception during request dispatching
/usr/lib/lua/luci/ucodebridge.lua:23: /usr/lib/lua/luci/model/sunpanel.lua:13: attempt to index local 'obj' (a nil value)

In error(), file [C]
called from function [anonymous function] (/usr/lib/lua/luci/ucodebridge.lua:23)
called from function ((tail call))
In [anonymous function](), file /usr/share/ucode/luci/runtime.uc, line 148, byte 45:
called from function [arrow function] (/usr/share/ucode/luci/dispatcher.uc:794:4)
called from function render ([C])
called from function render_action (/usr/share/ucode/luci/dispatcher.uc:768:24)
called from function run_action (/usr/share/ucode/luci/dispatcher.uc:795:4)
called from function [anonymous function] (/usr/share/ucode/luci/dispatcher.uc:1003:48)
called from anonymous function (/www/cgi-bin/luci:39:13)

` return lcall.call(modname, method, ...args);`
Near here ----------------------------------------^

分析并解决

经查/usr/lib/lua/luci/model/sunpanel.lua发现,导致该问题的核心源于是lsblk未返回正确结果。我所使用的系统并不自带lsblk命令,而且即使通过opkg安装也无法正常使用。

进一步读源码后认为该信息并不关键,故更改源码,从第6行起的sunpanel.blocks函数,直接返回空数组。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sunpanel.blocks = function()
--[[
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
local vals = {}
if f then
local ret = f:read("*all")
f:close()
local obj = jsonc.parse(ret)
for _, val in pairs(obj["blockdevices"]) do
local fsize = val["fssize"]
if fsize ~= nil and string.len(fsize) > 10 and val["mountpoint"] then
-- fsize > 1G
vals[#vals+1] = val["mountpoint"]
end
end
end
return vals
]]--
return {}
end

保存后刷新网页,即可正常使用。可手动指定配置文件路径为/etc/config/SunPanel


SunPanel报错:attempt to index local 'obj' (a nil value)
https://boyinthesun.cn/posts/f64900ef133a.html
作者
BoyInTheSun
发布于
2025年3月21日
许可协议