awesome icon indicating copy to clipboard operation
awesome copied to clipboard

single_shot in gears.timer not working with a lua error() in the callback

Open FluffyDango opened this issue 3 years ago • 1 comments

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:

  1. Create a timer with
gears.timer {
    timeout = 2,
    autostart = true,
    callback = function()
        test()
    end,
    single_shot = true
}
  1. In the test() callback add error() 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.

FluffyDango avatar Jul 30 '22 08:07 FluffyDango

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.

Aire-One avatar Aug 06 '22 15:08 Aire-One