diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-16 14:44:13 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-16 16:07:18 +0100 |
commit | 17f161df169a77670a25f739771d4ac6d22920c6 (patch) | |
tree | 7a34a630d763962a9c22c75986e3d68809929319 | |
parent | f86416d607d5a60d944167267e8348a0d4597b0b (diff) | |
download | lem-17f161df169a77670a25f739771d4ac6d22920c6.tar.gz lem-17f161df169a77670a25f739771d4ac6d22920c6.tar.xz lem-17f161df169a77670a25f739771d4ac6d22920c6.zip |
lem: print stack trace on error
..and clean up error messages.
-rw-r--r-- | bin/lem.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -99,7 +99,7 @@ ignore_sigpipe(void) struct sigaction act; if (sigaction(SIGPIPE, NULL, &act)) { - lem_log_error("error getting signal action: %s", + lem_log_error("lem: error getting signal action: %s", strerror(errno)); return -1; } @@ -107,7 +107,7 @@ ignore_sigpipe(void) act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, NULL)) { - lem_log_error("error setting signal action: %s", + lem_log_error("lem: error setting signal action: %s", strerror(errno)); return -1; } @@ -193,6 +193,15 @@ lem_queue(lua_State *T, int nargs) } static void +thread_error(lua_State *T) +{ + const char *msg = lua_tostring(T, -1); + + if (msg) + luaL_traceback(L, T, msg, 0); +} + +static void runqueue_pop(EV_P_ struct ev_idle *w, int revents) { struct lem_runqueue_slot *slot; @@ -247,8 +256,7 @@ runqueue_pop(EV_P_ struct ev_idle *w, int revents) #endif case LUA_ERRRUN: /* runtime error */ lem_debug("thread errored"); - /* move error message to L */ - lua_xmove(T, L, 1); + thread_error(T); break; case LUA_ERRMEM: /* out of memory */ @@ -284,7 +292,7 @@ queue_file(int argc, char *argv[], int fidx) oom(); default: - lem_log_error("%s", lua_tostring(T, 1)); + lem_log_error("lem: %s", lua_tostring(T, 1)); return -1; } @@ -308,7 +316,7 @@ main(int argc, char *argv[]) #else if (!ev_default_loop(LEM_LOOPFLAGS)) { #endif - lem_log_error("Error initializing event loop"); + lem_log_error("lem: error initializing event loop"); return EXIT_FAILURE; } @@ -318,7 +326,7 @@ main(int argc, char *argv[]) /* create main Lua state */ L = luaL_newstate(); if (L == NULL) { - lem_log_error("Error initializing Lua state"); + lem_log_error("lem: error initializing Lua state"); goto error; } luaL_openlibs(L); @@ -336,7 +344,7 @@ main(int argc, char *argv[]) /* initialize threadpool */ if (pool_init()) { - lem_log_error("Error initializing threadpool"); + lem_log_error("lem: error initializing threadpool"); goto error; } @@ -350,7 +358,7 @@ main(int argc, char *argv[]) /* if there is an error message left on L print it */ if (lua_type(L, -1) == LUA_TSTRING) - lem_log_error("%s", lua_tostring(L, -1)); + lem_log_error("lem: %s", lua_tostring(L, -1)); /* shutdown Lua */ lua_close(L); |