From dc9295d9817dbd75bbd2fa2427c116d99273bbe3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 13 Jul 2015 21:19:15 +0200 Subject: [PATCH] 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 --- lib/gears/timer.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/gears/timer.lua b/lib/gears/timer.lua index 02c9d278..cda03b3b 100644 --- a/lib/gears/timer.lua +++ b/lib/gears/timer.lua @@ -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() - self:emit_signal("timeout") - end) - if not success then - print(message) - end + local success, message = xpcall(function() + self:emit_signal("timeout") + end, function(err) + print(debug.traceback("Error during executing timeout handler: "..tostring(err))) + 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)