Permalink
Browse files

Include backtrace in error message when LuaErrors occur

Tested in both Lua and LuaJIT by passing (NaN,NaN,NaN) to ObjectRef::setvelocity().
  • Loading branch information...
1 parent 1fcea91 commit deda3a9e4479abb96dbcd9afa32d78bc9b45c38f @celeron55 committed Nov 1, 2015
Showing with 22 additions and 1 deletion.
  1. +5 −0 src/script/cpp_api/s_base.cpp
  2. +1 −0 src/script/cpp_api/s_base.h
  3. +14 −1 src/server.cpp
  4. +2 −0 src/server.h
@@ -231,6 +231,11 @@ void ScriptApiBase::stackDump(std::ostream &o)
o << std::endl;
}
+std::string ScriptApiBase::getBacktrace()
+{
+ return script_get_backtrace(getStack());
+}
+
void ScriptApiBase::setOriginDirect(const char *origin)
{
m_last_run_mod = origin ? origin : "??";
@@ -75,6 +75,7 @@ class ScriptApiBase {
void removeObjectReference(ServerActiveObject *cobj);
Server* getServer() { return m_server; }
+ std::string getBacktrace();
std::string getOrigin() { return m_last_run_mod; }
void setOriginDirect(const char *origin);
View
@@ -108,7 +108,14 @@ void *ServerThread::run()
} catch (con::ConnectionBindFailed &e) {
m_server->setAsyncFatalError(e.what());
} catch (LuaError &e) {
- m_server->setAsyncFatalError("Lua: " + std::string(e.what()));
+ std::ostringstream os(std::ios::binary);
+ os<<"Lua: "<<e.what();
+ std::string bt = m_server->getScriptBacktrace();
+ if(!bt.empty())
+ os<<std::endl<<bt;
+ else
+ os<<std::endl<<"No backtrace.";
+ m_server->setAsyncFatalError(os.str());
}
}
@@ -3114,6 +3121,12 @@ Inventory* Server::createDetachedInventory(const std::string &name)
return inv;
}
+std::string Server::getScriptBacktrace()
+{
+ MutexAutoLock lock(m_env_mutex);
+ return m_script->getBacktrace();
+}
+
// actions: time-reversed list
// Return value: success/failure
bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
View
@@ -293,6 +293,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
// Envlock and conlock should be locked when using scriptapi
GameScripting *getScriptIface(){ return m_script; }
+ std::string getScriptBacktrace();
+
// actions: time-reversed list
// Return value: success/failure
bool rollbackRevertActions(const std::list<RollbackAction> &actions,

0 comments on commit deda3a9

Please sign in to comment.