From 2354c6a62377e277b041c3e8667f3ccb38089b2d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 23 Oct 2011 15:59:15 +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 ++++++++++ globalconf.h | 3 +++ luaa.c | 25 +++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/awesome.c b/awesome.c index 58dc4e35..3d85cba9 100644 --- a/awesome.c +++ b/awesome.c @@ -339,6 +339,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 fcfb333f..fbe2b90b 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -9,6 +9,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/globalconf.h b/globalconf.h index 21251129..f255eb39 100644 --- a/globalconf.h +++ b/globalconf.h @@ -33,6 +33,7 @@ #include "objects/key.h" #include "color.h" #include "common/xembed.h" +#include "common/buffer.h" #define ROOT_WINDOW_EVENT_MASK \ (const uint32_t []) { \ @@ -87,6 +88,8 @@ typedef struct client_array_t stack; /** Lua VM state */ lua_State *L; + /** All errors messages from loading config files */ + buffer_t startup_errors; /** The event loop */ struct ev_loop *loop; /** The key grabber function */ diff --git a/luaa.c b/luaa.c index 474a3b64..256ed3bb 100644 --- a/luaa.c +++ b/luaa.c @@ -396,6 +396,13 @@ luaA_awesome_index(lua_State *L) lua_pushliteral(L, AWESOME_VERSION); else if(a_strcmp(buf, "release") == 0) lua_pushliteral(L, AWESOME_RELEASE); + else if(a_strcmp(buf, "startup_errors") == 0) + { + if (globalconf.startup_errors.len == 0) + return 0; + lua_pushstring(L, globalconf.startup_errors.s); + return 1; + } else return 0; @@ -632,6 +639,14 @@ luaA_init(xdgHandle* xdg) signal_add(&global_signals, "exit"); } +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) { @@ -644,7 +659,9 @@ luaA_loadrc(const char *confpath, bool run) 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. */ conffile = NULL; } @@ -658,7 +675,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; }