From a14320fc446991018f82a7900c2b0d126971a7f0 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Mon, 12 Feb 2024 22:58:26 +0100 Subject: [PATCH] Improve deprecation error messages --- src/script/common/c_internal.cpp | 2 +- src/script/lua_api/l_base.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp index b80ee6e40..ae83b8df0 100644 --- a/src/script/common/c_internal.cpp +++ b/src/script/common/c_internal.cpp @@ -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; } diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 03d8ee62d..921589816 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include #include +#include 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();