From be02406f7725bd28637b05f4b6ee51c09c82c34f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 23 Oct 2011 22:30:46 +0200 Subject: [PATCH] Signal config errors via a naughty popup If loading of any config file fails, awesome will now remember the error message and make it available to lua. The default config is modified to open a naughty popup on errors. This should help all those people who modify their config and then wonder why there change is ignored, not noticing awesome's error message on stderr Signed-off-by: Uli Schlachter --- awesome.c | 1 + awesomerc.lua.in | 10 ++++++++++ common/tokenize.gperf | 1 + globalconf.h | 3 +++ luaa.c | 22 ++++++++++++++++++++-- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/awesome.c b/awesome.c index aa153606c..a25c901ec 100644 --- a/awesome.c +++ b/awesome.c @@ -300,6 +300,7 @@ main(int argc, char **argv) p_clear(&globalconf, 1); globalconf.keygrabber = LUA_REFNIL; globalconf.mousegrabber = LUA_REFNIL; + buffer_init(&globalconf.startup_errors); /* save argv */ for(i = 0; i < argc; i++) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index e7f9b1c60..a17b8ee5b 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -7,6 +7,16 @@ require("beautiful") -- Notification library require("naughty") +-- {{{ Error handling +-- Check if awesome encountered an error during startup and fell back to +-- another config (This code will only ever execute for the fallback config) +if awesome.startup_errors then + naughty.notify({ preset = naughty.config.presets.critical, + title = "Oops, there were errors during startup!", + text = awesome.startup_errors }) +end +-- }}} + -- {{{ Variable definitions -- Themes define colours, icons, and wallpapers beautiful.init("@AWESOME_THEMES_PATH@/default/theme.lua") diff --git a/common/tokenize.gperf b/common/tokenize.gperf index 84cc0f343..2ba8fb2bd 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -95,6 +95,7 @@ skip_taskbar south start started +startup_errors sticky system systray diff --git a/globalconf.h b/globalconf.h index a1575c5cb..f68098b69 100644 --- a/globalconf.h +++ b/globalconf.h @@ -34,6 +34,7 @@ #include "color.h" #include "font.h" #include "common/xembed.h" +#include "common/buffer.h" typedef struct wibox_t wibox_t; typedef struct a_screen screen_t; @@ -81,6 +82,8 @@ typedef struct char *argv; /** Lua VM state */ lua_State *L; + /** All errors messages from loading config files */ + buffer_t startup_errors; /** Default colors */ struct { diff --git a/luaa.c b/luaa.c index d8d0229ee..a053fd96a 100644 --- a/luaa.c +++ b/luaa.c @@ -574,6 +574,10 @@ luaA_awesome_index(lua_State *L) case A_TK_RELEASE: lua_pushliteral(L, AWESOME_RELEASE); break; + case A_TK_STARTUP_ERRORS: + if (globalconf.startup_errors.len == 0) + return 0; + lua_pushstring(L, globalconf.startup_errors.s); default: return 0; } @@ -846,6 +850,14 @@ luaA_init(xdgHandle* xdg) lua_setfield(L, 1, "path"); /* package.path = "concatenated string" */ } +static void +luaA_startup_error(const char *err) +{ + if (globalconf.startup_errors.len > 0) + buffer_addsl(&globalconf.startup_errors, "\n\n"); + buffer_adds(&globalconf.startup_errors, err); +} + static bool luaA_loadrc(const char *confpath, bool run) { @@ -858,7 +870,9 @@ luaA_loadrc(const char *confpath, bool run) globalconf.conffile = a_strdup(confpath); if(lua_pcall(globalconf.L, 0, LUA_MULTRET, 0)) { - fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1)); + const char *err = lua_tostring(globalconf.L, -1); + luaA_startup_error(err); + fprintf(stderr, "%s\n", err); /* An error happened, so reset this. */ globalconf.conffile = NULL; } @@ -872,7 +886,11 @@ luaA_loadrc(const char *confpath, bool run) } } else - fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1)); + { + const char *err = lua_tostring(globalconf.L, -1); + luaA_startup_error(err); + fprintf(stderr, "%s\n", err); + } return false; }