Skip to content

Commit f5070b4

Browse files
sapiernerzhul
authored andcommittedJan 15, 2017
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
1 parent e12019c commit f5070b4

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed
 

Diff for: ‎src/emerge.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata,
564564
m_server->getScriptIface()->environment_OnGenerated(
565565
minp, maxp, m_mapgen->blockseed);
566566
} catch (LuaError &e) {
567-
m_server->setAsyncFatalError("Lua: " + std::string(e.what()));
567+
m_server->setAsyncFatalError("Lua: finishGen" + std::string(e.what()));
568568
}
569569

570570
EMERGE_DBG_OUT("ended up with: " << analyze_block(block));

Diff for: ‎src/script/common/c_converter.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ extern "C" {
2626
#include "util/serialize.h"
2727
#include "util/string.h"
2828
#include "common/c_converter.h"
29+
#include "common/c_internal.h"
2930
#include "constants.h"
3031

3132

3233
#define CHECK_TYPE(index, name, type) do { \
3334
int t = lua_type(L, (index)); \
3435
if (t != (type)) { \
36+
std::string traceback = script_get_backtrace(L); \
3537
throw LuaError(std::string("Invalid ") + (name) + \
3638
" (expected " + lua_typename(L, (type)) + \
37-
" got " + lua_typename(L, t) + ")."); \
39+
" got " + lua_typename(L, t) + ").\n" + traceback); \
3840
} \
3941
} while(0)
4042
#define CHECK_POS_COORD(name) CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER)

Diff for: ‎src/script/cpp_api/s_env.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ void ScriptApiEnv::environment_Step(float dtime)
5454
try {
5555
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
5656
} catch (LuaError &e) {
57-
getServer()->setAsyncFatalError(e.what());
57+
getServer()->setAsyncFatalError(
58+
std::string("environment_Step: ") + e.what() + "\n"
59+
+ script_get_backtrace(L));
5860
}
5961
}
6062

@@ -75,7 +77,9 @@ void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &t
7577
try {
7678
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
7779
} catch (LuaError &e) {
78-
getServer()->setAsyncFatalError(e.what());
80+
getServer()->setAsyncFatalError(
81+
std::string("player_event: ") + e.what() + "\n"
82+
+ script_get_backtrace(L) );
7983
}
8084
}
8185

@@ -237,7 +241,9 @@ void ScriptApiEnv::on_emerge_area_completion(
237241
try {
238242
PCALL_RES(lua_pcall(L, 4, 0, error_handler));
239243
} catch (LuaError &e) {
240-
server->setAsyncFatalError(e.what());
244+
server->setAsyncFatalError(
245+
std::string("on_emerge_area_completion: ") + e.what() + "\n"
246+
+ script_get_backtrace(L));
241247
}
242248

243249
lua_pop(L, 1); // Pop error handler

Diff for: ‎src/server.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ void *ServerThread::run()
107107
} catch (con::ConnectionBindFailed &e) {
108108
m_server->setAsyncFatalError(e.what());
109109
} catch (LuaError &e) {
110-
m_server->setAsyncFatalError("Lua: " + std::string(e.what()));
110+
m_server->setAsyncFatalError(
111+
"ServerThread::run Lua: " + std::string(e.what()));
111112
}
112113
}
113114

@@ -487,7 +488,7 @@ void Server::step(float dtime)
487488
g_settings->get("kick_msg_crash"),
488489
g_settings->getBool("ask_reconnect_on_crash"));
489490
}
490-
throw ServerError(async_err);
491+
throw ServerError("AsyncErr: " + async_err);
491492
}
492493
}
493494

1 commit comments

Comments
 (1)

rubenwardy commented on Jan 15, 2017

@rubenwardy
Contributor

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.