Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
FluffyDango opened this issue Jul 30, 2022 · 1 comment · May be fixed by #3669
Open

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

FluffyDango opened this issue Jul 30, 2022 · 1 comment · May be fixed by #3669
Assignees
Milestone

Comments

@FluffyDango
Copy link

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.

@Aire-One Aire-One self-assigned this Aug 6, 2022
Aire-One added a commit to Aire-One/awesome that referenced this issue Aug 6, 2022
@Aire-One Aire-One linked a pull request Aug 6, 2022 that will close this issue
@Aire-One
Copy link
Member

Aire-One commented Aug 6, 2022

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.

@sclu1034 sclu1034 linked a pull request Aug 8, 2022 that will close this issue
@Elv13 Elv13 added this to the v4.4 milestone Jan 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants