gears.timer: use xpcall with timeout and delayed calls

This provides a traceback in case of errors.

Ref: https://github.com/awesomeWM/awesome/issues/301
This commit is contained in:
Daniel Hahler 2015-07-13 21:19:15 +02:00
parent aca856b5d2
commit dc9295d981
1 changed files with 10 additions and 10 deletions

View File

@ -37,12 +37,11 @@ function timer:start()
return
end
self.data.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, self.data.timeout * 1000, function()
local success, message = pcall(function()
local success, message = xpcall(function()
self:emit_signal("timeout")
end, function(err)
print(debug.traceback("Error during executing timeout handler: "..tostring(err)))
end)
if not success then
print(message)
end
return true
end)
end
@ -107,10 +106,11 @@ end
local delayed_calls = {}
capi.awesome.connect_signal("refresh", function()
for _, callback in ipairs(delayed_calls) do
local success, message = pcall(unpack(callback))
if not success then
print(message)
end
local success, message = xpcall(function()
callback[1](unpack(callback, 2))
end, function(err)
print(debug.traceback("Error during delayed call: "..tostring(err)))
end)
end
delayed_calls = {}
end)