Fs widget issue on callback (missing "function" type check)
lecoredump opened this issue · comments
Install information
Running on Archlinux
$ awesome -v
awesome v4.3 (Too long)
• Compiled against Lua 5.3.5 (running with Lua 5.3)
• D-Bus support: ✔
• execinfo support: ✔
• xcb-randr version: 1.6
• LGI version: 0.9.2
$ lua5.3 -v
Lua 5.3.6 Copyright (C) 1994-2020 Lua.org, PUC-Rio
First observed on lain
version 6b3bdca (but same content observed on master latest commit)
Expected behaviour
No silent error (none displayed in the usual red popup, but present in X logs).
Steps to reproduce the problem
Use the following rc.lua
(no other configuration required)
local awful = require("awful")
local wibox = require("wibox")
local lain = require("lain")
local fsroothome = lain.widget.fs({
partition = "/home",
settings = function()
widget:set_markup(" " .. fs_now["/home"].percentage .. "% ")
end,
followtag = true,
})
awful.screen.connect_for_each_screen(function(s)
s.mylayoutbox = awful.widget.layoutbox(s)
s.mywibox = awful.wibar({ position = "top", screen = s, height = 18 })
s.mywibox:setup {
layout = wibox.layout.align.horizontal,
{
layout = wibox.layout.fixed.horizontal,
fsroothome,
},
}
end)
X error log
Obtained through awmtt, a script around Xephyr, results in
$ awmtt start -C rc.lua
2021-01-13 03:50:41 E: awesome: Error during a protected call: /usr/share/lua/5.3/lain/widget/fs.lua:141: attempt to call a table value (upvalue 'callback')
stack traceback:
/usr/share/lua/5.3/lain/widget/fs.lua:141: in function </usr/share/lua/5.3/lain/widget/fs.lua:138>
[C]: in function 'xpcall'
/usr/share/awesome/lib/gears/protected_call.lua:36: in function </usr/share/awesome/lib/gears/protected_call.lua:35>
(...tail calls...)
Caution: NOT using a test file (rc.lua)
Display: 1, Awesome PID: 84384, Xephyr PID: 84368
Possible fix
From what I could gather, it comes from the test performed on the callback
in the update
function (l.137) :
function fs.update(callback)
Gio.Async.start(gears.protected_call.call)(function()
update_synced()
if callback then
callback()
end
end)
end
Possible fix
The following type check seems to solve it , but considering I'm not a LUA developer (besides a couple of Nmap NSE scripts), I'd like your opinion if I'm missing something elsewhere, or if introspection is not the way to go here before opening a PR.
function fs.update(callback)
Gio.Async.start(gears.protected_call.call)(function()
update_synced()
if type(callback) == "function" then callback()
end)
end
Edit
I found the two other widgets that use a callback
in their update
function, alsabar
and pulsebar
, and both implement the same type check before calling :
if type(callback) == "function" then callback() end