Added lua tracebacks to some errors where you have been blind to what… (#5043)
authorsapier <sapier@users.noreply.github.com>
Sun, 15 Jan 2017 12:36:53 +0000 (13:36 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sun, 15 Jan 2017 12:36:53 +0000 (13:36 +0100)
* Added lua tracebacks to some errors where you have been blind to what actually went wrong

src/emerge.cpp
src/script/common/c_converter.cpp
src/script/cpp_api/s_env.cpp
src/server.cpp

index 3f0a46010c7bf320e23b9063c6967eb706afe489..1c9719c4898104d4e33638d277385aa1817a452b 100644 (file)
@@ -564,7 +564,7 @@ MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata,
                m_server->getScriptIface()->environment_OnGenerated(
                        minp, maxp, m_mapgen->blockseed);
        } catch (LuaError &e) {
-               m_server->setAsyncFatalError("Lua: " + std::string(e.what()));
+               m_server->setAsyncFatalError("Lua: finishGen" + std::string(e.what()));
        }
 
        EMERGE_DBG_OUT("ended up with: " << analyze_block(block));
index f36298915154b152975faca8416aa688533afccd..fc516d56a9acf5f03bbc99348d1939be0b818e0a 100644 (file)
@@ -26,15 +26,17 @@ extern "C" {
 #include "util/serialize.h"
 #include "util/string.h"
 #include "common/c_converter.h"
+#include "common/c_internal.h"
 #include "constants.h"
 
 
 #define CHECK_TYPE(index, name, type) do { \
                int t = lua_type(L, (index)); \
                if (t != (type)) { \
+                       std::string traceback = script_get_backtrace(L); \
                        throw LuaError(std::string("Invalid ") + (name) + \
                                " (expected " + lua_typename(L, (type)) + \
-                               " got " + lua_typename(L, t) + ")."); \
+                               " got " + lua_typename(L, t) + ").\n" + traceback); \
                } \
        } while(0)
 #define CHECK_POS_COORD(name) CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER)
index 913d8539d30f2cfd4008dc53b44dbbeecefc8ef7..b1404bf22d791f46986b66a3775708ad921cc9a1 100644 (file)
@@ -54,7 +54,9 @@ void ScriptApiEnv::environment_Step(float dtime)
        try {
                runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
        } catch (LuaError &e) {
-               getServer()->setAsyncFatalError(e.what());
+               getServer()->setAsyncFatalError(
+                               std::string("environment_Step: ") + e.what() + "\n"
+                               + script_get_backtrace(L));
        }
 }
 
@@ -75,7 +77,9 @@ void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &t
        try {
                runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
        } catch (LuaError &e) {
-               getServer()->setAsyncFatalError(e.what());
+               getServer()->setAsyncFatalError(
+                               std::string("player_event: ") + e.what() + "\n"
+                               + script_get_backtrace(L) );
        }
 }
 
@@ -237,7 +241,9 @@ void ScriptApiEnv::on_emerge_area_completion(
        try {
                PCALL_RES(lua_pcall(L, 4, 0, error_handler));
        } catch (LuaError &e) {
-               server->setAsyncFatalError(e.what());
+               server->setAsyncFatalError(
+                               std::string("on_emerge_area_completion: ") + e.what() + "\n"
+                               + script_get_backtrace(L));
        }
 
        lua_pop(L, 1); // Pop error handler
index 7380d37c2613ec9921a6ed8b253d79689f6724f6..29dce5a4ac4b47b9ccd2ed61ec936228fb6e891e 100644 (file)
@@ -107,7 +107,8 @@ void *ServerThread::run()
                } catch (con::ConnectionBindFailed &e) {
                        m_server->setAsyncFatalError(e.what());
                } catch (LuaError &e) {
-                       m_server->setAsyncFatalError("Lua: " + std::string(e.what()));
+                       m_server->setAsyncFatalError(
+                                       "ServerThread::run Lua: " + std::string(e.what()));
                }
        }
 
@@ -487,7 +488,7 @@ void Server::step(float dtime)
                                g_settings->get("kick_msg_crash"),
                                g_settings->getBool("ask_reconnect_on_crash"));
                }
-               throw ServerError(async_err);
+               throw ServerError("AsyncErr: " + async_err);
        }
 }