From: Florian Forster Date: Thu, 25 Nov 2010 12:18:30 +0000 (+0100) Subject: lua plugin: Be more verbose when loading a script fails. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8799d1d743533efe2aa111c59929721b122c93f1;p=collectd.git lua plugin: Be more verbose when loading a script fails. --- diff --git a/src/lua.c b/src/lua.c index f0724514..58c96ade 100644 --- a/src/lua.c +++ b/src/lua.c @@ -306,21 +306,31 @@ static int lua_script_load (const char *script_path) /* {{{ */ return (-1); } - status = luaL_dofile (script->lua_state, script->script_path); + status = luaL_loadfile (script->lua_state, script->script_path); + if (status != 0) + { + ERROR ("lua plugin: luaL_loadfile failed with status %i", status); + lua_script_free (script); + return (-1); + } + + status = lua_pcall (script->lua_state, + /* nargs = */ 0, + /* nresults = */ LUA_MULTRET, + /* errfunc = */ 0); if (status != 0) { const char *errmsg; - switch (status) - { - case LUA_ERRSYNTAX: errmsg = "Syntax error"; break; - case LUA_ERRFILE: errmsg = "File I/O error"; break; - case LUA_ERRMEM: errmsg = "Memory allocation error"; break; - default: errmsg = "Unexpected error"; - } + errmsg = lua_tostring (script->lua_state, /* stack pos = */ -1); - ERROR ("lua plugin: Loading script \"%s\" failed: %s", - script->script_path, errmsg); + if (errmsg == NULL) + ERROR ("lua plugin: lua_pcall failed with status %i. " + "In addition, no error message could be retrieved from the stack.", + status); + else + ERROR ("lua plugin: Executing script \"%s\" failed:\n%s", + script->script_path, errmsg); lua_script_free (script); return (-1);