single_shot in gears.timer not working with a lua error() in the callback
Output of awesome --version:
awesome v4.3 (Too long) • Compiled against Lua 5.3.6 (running with Lua 5.3) • D-Bus support: ✔ • execinfo support: ✔ • xcb-randr version: 1.6 • LGI version: 0.9.2
How to reproduce the issue:
- Create a timer with
gears.timer {
timeout = 2,
autostart = true,
callback = function()
test()
end,
single_shot = true
}
- In the
test()callback adderror()Example:
local function test()
naughty.notify({ text = "One" })
naughty.notify({ text = "Two" })
error("give error")
end
Actual result:
The callback keeps going without stopping and no error is given.
Expected result:
It should only run once, give an error and stop.
Hello,
Throwing an error in the callback results in breaking the execution of the emit_signal method. I have proposed a fix that mitigates the issue.
There is also something you can do on the user side : catching the error in the callback.
gears.timer {
timeout = 2,
autostart = true,
callback = function()
local status, result = pcall(test)
if not status then
naughty.notify({ text = result })
end
end,
single_shot = true
}
Obviously, this "user level fix" wouldn't work if this is the callback itself that throw the error. So the proposed PR is still required to correctly mitigate the issue.