Improve deprecation error messages

This commit is contained in:
Lars Mueller 2024-02-12 22:58:26 +01:00
parent eb52a149a0
commit a14320fc44
2 changed files with 8 additions and 4 deletions

@ -189,7 +189,7 @@ void log_deprecated(lua_State *L, std::string message, int stack_depth, bool onc
}
if (mode == DeprecatedHandlingMode::Error)
script_error(L, LUA_ERRRUN, nullptr, nullptr);
throw LuaError(message);
else if (log)
infostream << script_get_backtrace(L) << std::endl;
}

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include <algorithm>
#include <cmath>
#include <sstream>
ScriptApiBase *ModApiBase::getScriptApiBase(lua_State *L)
{
@ -147,11 +148,14 @@ int ModApiBase::l_deprecated_function(lua_State *L, const char *good, const char
== deprecated_logged.end()) {
deprecated_logged.emplace_back(hash);
warningstream << "Call to deprecated function '" << bad << "', please use '"
<< good << "' at " << backtrace << std::endl;
std::stringstream msg;
msg << "Call to deprecated function '" << bad << "', use '" << good << "' instead";
warningstream << msg.str() << " at " << backtrace << std::endl;
if (dep_mode == DeprecatedHandlingMode::Error)
script_error(L, LUA_ERRRUN, NULL, NULL);
throw LuaError(msg.str());
}
u64 end_time = porting::getTimeUs();