Replace various calls to warn() with luaA_warn()

luaA_warn() prints a Lua backtrace and thus generates more useful output. warn()
should only be used in awesome-internal places (e.g. receiving an error from the
X11 server).

Closes https://github.com/awesomeWM/awesome/pull/608.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2015-12-23 14:01:10 +01:00 committed by Daniel Hahler
parent 5cbd4402d9
commit 5e6a893207
4 changed files with 15 additions and 17 deletions

View File

@ -254,7 +254,7 @@ signal_object_emit(lua_State *L, signal_array_t *arr, const char *name, int narg
luaA_dofunction(L, nargs, 0); luaA_dofunction(L, nargs, 0);
} }
} else } else
warn("Trying to emit unknown signal '%s'", name); luaA_warn(L, "Trying to emit unknown signal '%s'", name);
/* remove args */ /* remove args */
lua_pop(L, nargs); lua_pop(L, nargs);
@ -273,11 +273,11 @@ luaA_object_emit_signal(lua_State *L, int oud,
lua_class_t *lua_class = luaA_class_get(L, oud); lua_class_t *lua_class = luaA_class_get(L, oud);
lua_object_t *obj = luaA_toudata(L, oud, lua_class); lua_object_t *obj = luaA_toudata(L, oud, lua_class);
if(!obj) { if(!obj) {
warn("Trying to emit signal '%s' on non-object", name); luaA_warn(L, "Trying to emit signal '%s' on non-object", name);
return; return;
} }
else if(lua_class->checker && !lua_class->checker(obj)) { else if(lua_class->checker && !lua_class->checker(obj)) {
warn("Trying to emit signal '%s' on invalid object", name); luaA_warn(L, "Trying to emit signal '%s' on invalid object", name);
return; return;
} }
signal_t *sigfound = signal_array_getbyid(&obj->signals, signal_t *sigfound = signal_array_getbyid(&obj->signals,
@ -304,8 +304,10 @@ luaA_object_emit_signal(lua_State *L, int oud,
lua_remove(L, - nargs - nbfunc - 2 + i); lua_remove(L, - nargs - nbfunc - 2 + i);
luaA_dofunction(L, nargs + 1, 0); luaA_dofunction(L, nargs + 1, 0);
} }
} else } else {
warn("Trying to emit unknown signal '%s'", name); luaA_warn(L, "Trying to emit unknown signal '%s'", name);
return;
}
/* Then emit signal on the class */ /* Then emit signal on the class */
lua_pushvalue(L, oud); lua_pushvalue(L, oud);

View File

@ -91,14 +91,14 @@ luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len)
if(!g_utf8_validate(str, -1, NULL)) if(!g_utf8_validate(str, -1, NULL))
{ {
warn("failed to convert \"%s\" into keysym (invalid UTF-8 string)", str); luaA_warn(L, "failed to convert \"%s\" into keysym (invalid UTF-8 string)", str);
return; return;
} }
length = g_utf8_strlen(str, -1); /* This function counts combining characters. */ length = g_utf8_strlen(str, -1); /* This function counts combining characters. */
if(length <= 0) if(length <= 0)
{ {
warn("failed to convert \"%s\" into keysym (empty UTF-8 string)", str); luaA_warn(L, "failed to convert \"%s\" into keysym (empty UTF-8 string)", str);
return; return;
} }
else if(length > 1) else if(length > 1)
@ -107,7 +107,7 @@ luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len)
if(g_utf8_strlen(composed, -1) != 1) if(g_utf8_strlen(composed, -1) != 1)
{ {
p_delete(&composed); p_delete(&composed);
warn("failed to convert \"%s\" into keysym (failed to compose a single character)", str); luaA_warn(L, "failed to convert \"%s\" into keysym (failed to compose a single character)", str);
return; return;
} }
unicode = g_utf8_get_char(composed); unicode = g_utf8_get_char(composed);
@ -118,7 +118,7 @@ luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len)
if(unicode == (gunichar)-1 || unicode == (gunichar)-2) if(unicode == (gunichar)-1 || unicode == (gunichar)-2)
{ {
warn("failed to convert \"%s\" into keysym (neither keysym nor single unicode)", str); luaA_warn(L, "failed to convert \"%s\" into keysym (neither keysym nor single unicode)", str);
return; return;
} }
@ -132,7 +132,7 @@ luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len)
key->keysym = unicode | (1 << 24); key->keysym = unicode | (1 << 24);
else else
{ {
warn("failed to convert \"%s\" into keysym (unicode out of range): \"%u\"", str, unicode); luaA_warn(L, "failed to convert \"%s\" into keysym (unicode out of range): \"%u\"", str, unicode);
return; return;
} }
} }

View File

@ -295,7 +295,7 @@ luaA_window_set_type(lua_State *L, window_t *w)
type = WINDOW_TYPE_NORMAL; type = WINDOW_TYPE_NORMAL;
else else
{ {
warn("Unknown window type '%s'", buf); luaA_warn(L, "Unknown window type '%s'", buf);
return 0; return 0;
} }

View File

@ -419,9 +419,7 @@ luaA_spawn(lua_State *L)
if(!argv || !argv[0]) if(!argv || !argv[0])
{ {
g_strfreev(argv); g_strfreev(argv);
/* push error on stack */ luaA_warn(L, "spawn: parse error: %s", error->message);
lua_pushfstring(L, "spawn: parse error: %s", error->message);
warn("%s", lua_tostring(L, -1));
g_error_free(error); g_error_free(error);
return 1; return 1;
} }
@ -447,9 +445,7 @@ luaA_spawn(lua_State *L)
g_strfreev(argv); g_strfreev(argv);
if(!retval) if(!retval)
{ {
/* push error on stack */ luaA_warn(L, "%s", error->message);
lua_pushstring(L, error->message);
warn("%s", lua_tostring(L, -1));
g_error_free(error); g_error_free(error);
if(context) if(context)
sn_launcher_context_complete(context); sn_launcher_context_complete(context);