Merge branch 'better-error-handling'

Closes https://github.com/awesomeWM/awesome/pull/311
This commit is contained in:
Daniel Hahler 2015-07-22 13:54:56 +02:00
commit 5a9ec82b95
7 changed files with 31 additions and 22 deletions

15
event.c
View File

@ -116,11 +116,11 @@ event_handle_mousegrabber(int x, int y, uint16_t mask)
if(globalconf.mousegrabber != LUA_REFNIL)
{
lua_State *L = globalconf_get_lua_State();
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.mousegrabber);
mousegrabber_handleevent(L, x, y, mask);
if(lua_pcall(L, 1, 1, 0))
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.mousegrabber);
if(!luaA_dofunction(L, 1, 1))
{
warn("error running function: %s", lua_tostring(L, -1));
warn("Stopping mousegrabber.");
luaA_mousegrabber_stop(L);
}
else if(!lua_isboolean(L, -1) || !lua_toboolean(L, -1))
@ -599,16 +599,17 @@ event_handle_key(xcb_key_press_event_t *ev)
if(globalconf.keygrabber != LUA_REFNIL)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.keygrabber);
if(keygrabber_handlekpress(L, ev))
{
if(lua_pcall(L, 3, 1, 0))
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.keygrabber);
if(!luaA_dofunction(L, 3, 1))
{
warn("error running function: %s", lua_tostring(L, -1));
warn("Stopping keygrabber.");
luaA_keygrabber_stop(L);
}
lua_pop(L, 1);
}
lua_pop(L, 1); /* pop returned value or function if not called */
}
else
{

View File

@ -20,9 +20,9 @@ local keygrabbing = false
local function grabber(mod, key, event)
for i, g in ipairs(grabbers) do
for i, keygrabber_function in ipairs(grabbers) do
-- continue if the grabber explicitly returns false
if g(mod, key, event) ~= false then
if keygrabber_function(mod, key, event) ~= false then
break
end
end

View File

@ -161,8 +161,8 @@ function tasklist.new(screen, filter, buttons, style, update_function, base_widg
-- Add a delayed callback for the first update.
if not queued_update then
timer.delayed_call(function()
queued_update = false
tasklist_update(screen, w, buttons, filter, data, style, uf)
queued_update = nil
end)
queued_update = true
end

View File

@ -103,7 +103,8 @@ function beautiful.init(config)
if type(config) == 'string' then
-- Expand the '~' $HOME shortcut
config = config:gsub("^~/", homedir .. "/")
success, theme = pcall(function() return dofile(config) end)
success, theme = xpcall(function() return dofile(config) end,
debug.traceback)
elseif type(config) == 'table' then
success = true
theme = config

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()
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)

5
luaa.h
View File

@ -56,6 +56,9 @@ luaA_warn(lua_State *L, const char *fmt, ...)
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
luaL_traceback(L, L, NULL, 2);
fprintf(stderr, "%s\n", lua_tostring(L, -1));
}
static inline int
@ -63,6 +66,8 @@ luaA_typerror(lua_State *L, int narg, const char *tname)
{
const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, luaL_typename(L, narg));
luaL_traceback(L, L, NULL, 2);
lua_concat(L, 2);
return luaL_argerror(L, narg, msg);
}

View File

@ -29,7 +29,9 @@ runner.run_steps = function(steps)
local step_as_string = step..'/'..#steps..' (@'..step_count..')'
-- Call the current step's function.
local success, result = pcall(steps[step], step_count)
local success, result = xpcall(function()
return steps[step](step_count)
end, debug.traceback)
if not success then
io.stderr:write('Error: running function for step '