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