Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added lua tracebacks to some errors where you have been blind to what… (
#5043)

* Added lua tracebacks to some errors where you have been blind to what actually went wrong
  • Loading branch information
sapier authored and nerzhul committed Jan 15, 2017
1 parent e12019c commit f5070b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/emerge.cpp
Expand Up @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion src/script/common/c_converter.cpp
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/script/cpp_api/s_env.cpp
Expand Up @@ -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));
}
}

Expand All @@ -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) );
}
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/server.cpp
Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down

1 comment on commit f5070b4

@rubenwardy
Copy link
Member

@rubenwardy rubenwardy commented on f5070b4 Jan 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note we're supposed to use imperative commit messages: http://dev.minetest.net/Git_Guidelines#Upstream_commit_rules

Also, avoid overflowing the first line. So it should have been:

Add missing tracebacks and callback names to some Lua errors

or similar

Please sign in to comment.