Awesome developers!

While editing rc.lua, typos not resulting in syntax errors currently
result in (usually) unusable setup of awesome.
Syntax errors make awesome fallback to the default config, but
exceptions do not.

I propose luaA_loadrc() to return false on exception (lua_pcall()
failure), allowing a next (default) config file to be read. The lua
state could be already damaged/partially initialized, but I guess this
"best effort" is better than the current solution. In my experience,
this may lead to things such as multiple taglists in the status bar
(depending on the runtime error).

A best solution would be to
1) clone Lua state before lua_pcall(), but there does not seem to be a
simple way to do it
2) create new lua state, but that would require re-run of luaA_init(),
ewmh_init(), systray_init() and spawn_init().
3) restart awesome with the default config. This would also solve
problems in config that happen later (callback function errors).


Cheers,
  Tomas Gavenciak
From c33a56a766a7fc99f70220df50578c5e26689436 Mon Sep 17 00:00:00 2001
From: Tomas Gavenciak <[email protected]>
Date: Sun, 6 Jun 2010 15:58:36 +0200
Subject: [PATCH] Change handling of invalid config files
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Unhandled exception in (succesfully parsed) config
file now returns false in luaA_loadrc(). This
means that (possible) following configs are tried.

The partially executed config file could leave the
state completely unusable, but hopefully (and
probably) did not.

Signed-off-by: Tomas Gavenciak <[email protected]>
---
 luaa.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/luaa.c b/luaa.c
index b994623..479ac72 100644
--- a/luaa.c
+++ b/luaa.c
@@ -825,7 +825,13 @@ luaA_loadrc(const char *confpath, bool run)
         if(run)
         {
             if(lua_pcall(globalconf.L, 0, LUA_MULTRET, 0))
-                fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
+	    {
+                warn("exception evaluating config file %s:\n%s", 
+                    confpath, lua_tostring(globalconf.L, -1));
+                warn("trying next config file in potentially unstable state");
+                lua_pop(globalconf.L, 1);
+                return false;
+	    }
             else
             {
                 conffile = a_strdup(confpath);
@@ -833,8 +839,10 @@ luaA_loadrc(const char *confpath, bool run)
             }
         }
         else
+        {
             lua_pop(globalconf.L, 1);
-        return true;
+            return true;
+        }
     }
     else
         fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
-- 
1.7.0.4

Reply via email to